sas-macro

SAS data step view and data wrap in a macro for loop

流过昼夜 提交于 2019-12-31 05:28:07
问题 For a university research project I am retrieving data from WRDS via SAS and am relatively new to SAS. I am trying to retrieve data in a specific interval provided by WRDS which actually works very for me; the structure is as follows [1]Define some macro variable [2]Use data step view [3]Make manipulation on data [4]Export the data to csv In particular I am retrieving data for a stock for every single year. Instead of changing the variable all the time a macro that would allow me to provide

How to create a macro variable within a macro?

廉价感情. 提交于 2019-12-25 02:46:29
问题 I am wondering how to create a SAS macro variable within a block of SAS %MACRO statement? It appears that my CALL SYMPUT or my SELECT INTO statements aren't working when they are in a block of %MACRO statement. %MACRO NONDATE_FORMAT_CHECK(varname=,output=); PROC SQL; CONNECT TO NETEZZA AS NET (SERVER=&server DATABASE=&database USER=&NBKID PASSWORD=&NBKPASSWD); CREATE TABLE WORK.DT_FMT&output AS SELECT * FROM CONNECTION TO NET (SELECT 'FORMAT_IS_DATE' AS DT_FMT_INDICATOR FROM &input_database

Invoke a Macro Using A Macro Variable Name

冷暖自知 提交于 2019-12-25 02:16:05
问题 Is it possible in SAS to invoke a call to a macro using a macro variable whose value is the macro's name? Something like the following: %MACRO TEST (macroName, var1, var2, var3, var4, var5); %put LOG: %&macroName(&var1); %MEND; %TEST(testName,testVar1); In response to Richard's answer. I tried following your solution, but am still getting an "apparent invocation of macro YearMonthString not resolved" using the following code: %MACRO YearMonthString(nYear,nMonth); /* Builds a string in the

Macro looping over columns in SAS broken by ods

∥☆過路亽.° 提交于 2019-12-24 22:17:09
问题 I just found that ods graphics / reset; broke my loop. I am still curious why this happened and if there are other potential similar pitfalls. Objective: I want to loop over columns in SAS and provide a plot where the x variable remains constant, but the y dimension varies. I could transpose and use a by statement. I don't want to do that. Problem: Despite the log with options mprint ; showing the text replacement is working properly, the outputted plots only display the final plot repeatedly

count the values in one column by SQL - using SAS

北慕城南 提交于 2019-12-24 18:51:44
问题 I have a customer_no and class . I would like to calculate ratio from the same column for each customer. ratio= (number of secured/ total number classes) customer_no class 1 unsecured 1 secured 1 secured 2 unsecured 2 secured 3 secured 3 unsecured 3 secured 3 unsecured The output sample will be customer_no ratio 1 0.666 2 0.50 3 0.50 . . . 20000 回答1: You can calculate ratio in a query like this: select customer_no, (count(case when class = 'secured' then 1 end) -- count if class is secured +0

SAS Macro for multiple datasets

我的梦境 提交于 2019-12-24 13:43:18
问题 I am new to SAS. I have 12(Monthly data) data sets in a folder. Names of data sets are: 201401 201402 201403 ... 201411 201412 Each data contain 10 Variables. Variable names are same for all data. I want only 3 Variables among 10 and rename data by new_201401 and so on. I am trying it manually by using Keep Var1 Var2 Var3; but is there any easy way or macro so we can make it fast? Thanks in advance. 回答1: I think this will do the trick: %macro keep(table,var1,var2,var3,set); data &table (keep=

SAS Macro function conditional on value of Macro Variable

*爱你&永不变心* 提交于 2019-12-24 13:05:14
问题 I have a SAS project (EGv7.1) that allows the user to specify a value on the first line. Then, other processes are invoked based on the value specified. One of these is that some other macro variables are assigned. Below is what I have, and it does not seem to be working. I really need the let statement to be first in the sequence, but besides that I am open to changes. Any suggestions? %let number=8; %macro my_function(); %if &number=8 %then %do; %let number_text=eight; %let number_text_2

how to pass a string to a macro sas without special char

↘锁芯ラ 提交于 2019-12-24 03:55:26
问题 I wrote this macro in sas to have some information about some files : %macro info_1(cmd); filename dirList pipe &cmd.; data work.dirList; infile dirList length=reclen; input file $varying200. reclen; permission=scan(file,1,""); if input(scan(file,2,""), 8.)=1; user=scan(file,3,""); group=scan(file,4,""); file_size_KB=round(input(scan(file,5,""), 8.)/1024,1); file_size_MB=round(input(scan(file,5,""), 8.)/1024/1024,1); modified_time=input(catx(" ",scan(file,6," "),scan(file,7,"")),anydtdtm.);

SAS SQL Macro Incremental Date Range

雨燕双飞 提交于 2019-12-24 01:16:08
问题 I am currently having trouble using an incrementing data range to output a table that uses a table filled with Emails with JobOffers that have already been renamed using VBA - this is more for my own learning than anything else. I want the code to loop through the days I can set in a macro command %EmailDump('01Jan2015'd,'02Jan2015') And it will run the Macro in the code below and allow me to pull back all emails from within that period and export it (I understand I am over writing the table

SAS - Dynamically create column names using the values from another column

半世苍凉 提交于 2019-12-23 16:01:29
问题 I Have a column with many flags that were parsed from a XML parser. Data looks like this: USERKEYED=Y;VALMATCH=N;DEVICEVERIFIED=N;EXCEPTION=N;USERREGISTRD=N;ASSOCIATE=Y;EXTERNAL=N;GROSSGIVEN=Y;UMAPPED=N; I have to create a table with all these column names to capture the flags. Like: USERKEYED VALMATCH DEVICEVERIFIED EXCEPTION USERREGISTRD ASSOCIATE EXTERNAL GROSSGIVEN UMAPPED Y N N N N Y N Y N Y N N N N Y Y Y N Y N N Y N Y N Y N How can I capture values dynamically in SAS? Either in a DATA