sas-macro

SAS macro if then condition compare variable with numeric value

落爺英雄遲暮 提交于 2019-12-02 14:05:02
问题 I have a data set that include several paths and the last variable is the frequency of the people following the path. data path; input path1 path2 path3 path4 path5 path6 frequency; cards; 2 5 3 6 7 2 465 4 3 2 3 0 0 20394 2 1 3 6 5 0 309 1 3 2 6 5 3 302 2 2 5 4 7 7 6783 ; run; I would like to calculate the frequency from the former stop to the latter stop along each path to count their individual frequency. since there are 7 stops. there will be 49 combinations, so I wrote a macro code.

Prompt or Macro Variables used in calculations

本秂侑毒 提交于 2019-12-02 00:34:30
问题 I have created a numeric variable using the Prompt Manager in EG. This variable is called HYr for the highest year of data that I am pulling. When running the program I create 4 new variables based on the highest year and this is where I am having issues. I have the following: %Let Yr2 = &HYr. - 1; %Let Yr3 = "&HYr." - 2; %Let Yr4 = &HYr. - 3; %Let Yr5 = '&HYr.' - 4; I am trying to subtract the value from the year and the new variable will be used in determining date ranges that are being

SAS Macro, passing value as string to where clause

本小妞迷上赌 提交于 2019-12-01 22:31:39
I have a SAS macro below that is not working--- this snippet returns no values because the where statement doesn't work. Anyone have any ideas? I tried adding %str but that didn't work either. %macro refreshments(beverage_type=); proc sql; select * where drink_type = '&beverage_type.' ; quit; %mend %refreshments(Sprite); Thanks. Macro variables will not resolve in single quotes. You are also missing the FROM clause, and the macro parameter was being provided as positional (instead of name=value pair). Try the following: %macro refreshments(beverage_type=); proc sql; select * from YOURTABLE

Prompt or Macro Variables used in calculations

戏子无情 提交于 2019-12-01 20:30:45
I have created a numeric variable using the Prompt Manager in EG. This variable is called HYr for the highest year of data that I am pulling. When running the program I create 4 new variables based on the highest year and this is where I am having issues. I have the following: %Let Yr2 = &HYr. - 1; %Let Yr3 = "&HYr." - 2; %Let Yr4 = &HYr. - 3; %Let Yr5 = '&HYr.' - 4; I am trying to subtract the value from the year and the new variable will be used in determining date ranges that are being pulled. I am trying several things and learning in the process but I am still stuck. I know it is probably

Efficiently reformat data layout

耗尽温柔 提交于 2019-12-01 14:50:49
I have several Excel spreadsheets with data layout like this raw data : company company1 company2 company3 currency $ Y E 1/1/2013 32.68 12 3 1/2/2013 12.5 13 4 1/3/2013 45 45 8 which basically are time series data grouped together. I need the final layout transformed into panel data, like this wanted panel data : Since my observations are usually very large, it is not practical manually to reformat it. Is there a macro code that can achieve such a goal? pnuts Turn on Record Macro if desired. In Excel, move the currency row out of the way. 'Reverse pivot' (as detailed here ), sort the Table on

Efficiently reformat data layout

余生颓废 提交于 2019-12-01 13:27:49
问题 I have several Excel spreadsheets with data layout like this raw data: company company1 company2 company3 currency $ Y E 1/1/2013 32.68 12 3 1/2/2013 12.5 13 4 1/3/2013 45 45 8 which basically are time series data grouped together. I need the final layout transformed into panel data, like this wanted panel data: Since my observations are usually very large, it is not practical manually to reformat it. Is there a macro code that can achieve such a goal? 回答1: Turn on Record Macro if desired. In

SAS Macro coding

好久不见. 提交于 2019-12-01 13:24:32
I dont understand what is going on in my SAS code. The code behaves as expected, but only during the first time it compiles, i.e. the table called 'SummaryTable' shows the correct 'LogLik' value for each of the 3 iterations where the code triggers %mylogreg and %ModelsSummary. However, if I re-run the code then it behaves differently, the 'LogLik' value for the 3 iterations is the same and it is equal to the value for the last iteration. So, in some way the variable 'MyLogLik' saved the value of the third iteration during the first time the code is compiled. Fist data generation step: data

using quotes in sas macro filename pipe

╄→尐↘猪︶ㄣ 提交于 2019-12-01 12:22:10
问题 I am using the following Macro that uses filename pipe. But get an error saying invalid option name "dir", etc. I suspect it could be due to the quotes while defining filename and pipe. I guess it recognizes it as an option. I tried to remove the quote, removing %bquote and having just the double quote, but still keep getting the errors. I am using Windows, but will also be running it remotely on Linux. Any thoughts would be deeply appreciated. %macro setprogvar(dateval); %global date; %let

Testing for an empty parameter in a SAS Macro

天涯浪子 提交于 2019-12-01 09:17:47
For example, i have a macro program %macro test(parameter1= , parameter2=, parameter3=); DATA data_gender; SET data_input(WHERE=(gender=parameter3)); RUN; ..... %mend; Basically, i made a selection of observations using the parameter3 (Male or Female). Now i want to create a third option: to keep both observations in Male and Female when the parameter3 is empty (without declaring the value of this parameter). %test(parameter1=xxx , parameter2=yyy, parameter3=); Can you tell me how can i do that please? For this answer I will cite Chang Chung's seminal paper, "Is This Macro Parameter Blank" ,

Testing for an empty parameter in a SAS Macro

≡放荡痞女 提交于 2019-12-01 07:08:05
问题 For example, i have a macro program %macro test(parameter1= , parameter2=, parameter3=); DATA data_gender; SET data_input(WHERE=(gender=parameter3)); RUN; ..... %mend; Basically, i made a selection of observations using the parameter3 (Male or Female). Now i want to create a third option: to keep both observations in Male and Female when the parameter3 is empty (without declaring the value of this parameter). %test(parameter1=xxx , parameter2=yyy, parameter3=); Can you tell me how can i do