SAS Macro Code Variable Creation -
i'd create multiple flags in dataset (and many derived numeric characteristics), struggling code work.
i using iterative loop conditions. or suggestions on resolutions appreciated.
here code tried, creates flag, not variable in new dataset.
%macro gb1(howmany); %do i=1 %to &howmany; %if status&i = 1 %then %let &gb1_&i = 1; %else %if status&i = 2 %then %let &gb1_&i = 1; %else %if dpd&i >= 2 %then %let &gb1_&i = 1; %else %if ((dpd&i < 2) , (dpd&i >= 1)) %then %let &gb1_&i = 2; %else %let &gb1_&i = 1; %end; %mend gb1; data test; set y2014.perf_data_derive (where=((dpd15 <= 2) , (prod = 1)));; %gb1(36); run; i appreciate can get, in advance.
%if, %then, %else etc. macro statements , used evaluate expressions macro variables in order conditionally submit pieces of sas code. seems you're not trying of that; want repeat data step statements involve variables in data set (not macro variables). this, use statements in data step:
%macro gb1(howmany); %do i=1 %to &howmany; if status&i = 1 gb1_&i = 1; else if status&i = 2 gb1_&i = 1; else if dpd&i >= 2 gb1_&i = 1; else if ((dpd&i < 2) , (dpd&i >= 1)) gb1_&i = 2; else let gb1_&i = 1; %end; %mend gb1;
Comments
Post a Comment