Hi,
I have data set and i want to generate dynamic code is it possible to generate dynamic code from existing sas data sets.
This is the datatsets .
DATA rule;
INFILE DATALINES DELIMITER=',' DSD;
INPUT val1 $ val2 $ val3 $ val4 $;
DATALINES;
1,,3,4
68,89,80,,
87,,,12
RUN;
i want to generate dynamic code like multiple if condition is given below for above data set. is it possible to generate if data is very large and have many different number of combinations.
if val1='1' and val2='' and val3='3' val4='4' then
do;
end;
if val1='68' and val2='89' and val3='80' val4='' then
do;
end;
if val1='87' and val2='' and val3='' val4='12' then
do;
end;
I am interpreting the question you are asking a little differently. I think you want to make the "generated code" available at a later date. For example, here is how the program could construct a separate file holding the generated code.
data _null_;
set rule;
file 'path to some file of your choice' noprint;
put "if val1='" val1 +(-1) "' and val2='" val2 +(-1)
"' and val3='" val3 +(-1) "' and val4='" val4 +(-1) "' then";
put " do;"
/ " end;"
/ ;
run;
As with any long series of IF/THEN statements, consider whether it would be wise to add the word ELSE.
When this DATA step is over, the file that you have specified in quotes in the FILE statement will hold the code you are asking for. You might edit that code to fill in what needs to be done, before %INCLUDE brings it in.
Follow the basic macro development scheme:
Once such a macro works, you can create a control dataset that contains your series of parameters, and use call execute off that.
I am interpreting the question you are asking a little differently. I think you want to make the "generated code" available at a later date. For example, here is how the program could construct a separate file holding the generated code.
data _null_;
set rule;
file 'path to some file of your choice' noprint;
put "if val1='" val1 +(-1) "' and val2='" val2 +(-1)
"' and val3='" val3 +(-1) "' and val4='" val4 +(-1) "' then";
put " do;"
/ " end;"
/ ;
run;
As with any long series of IF/THEN statements, consider whether it would be wise to add the word ELSE.
When this DATA step is over, the file that you have specified in quotes in the FILE statement will hold the code you are asking for. You might edit that code to fill in what needs to be done, before %INCLUDE brings it in.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.