Hi All
I have the following dataset
pgmname
adae
adsl
adcm
I need to generate a sas program from the above dataset with the code:
%run(dataset=adsl);
%run(dataset=adae);
%run(dataset=adcm);
How can i achieve this? Any thoughts, thanks in advance!
Use
data _null_;
set have;
call execute('%nrstr(%run(dataset='!!trim(pgmname)!!'))');
run;
@SASSLICK001 wrote:
Hi All
I have the following dataset
pgmname
adae
adsl
adcm
I need to generate a sas program from the above dataset with the code:
%run(dataset=adsl);
%run(dataset=adae);
%run(dataset=adcm);
How can i achieve this? Any thoughts, thanks in advance!
@SASSLICK001 wrote:
thanks Kurt for the quick reply, may i know where these records are being written, I wanted to write to a file for example : temp.sas
According to your own post, you wanted to run a macro repeatedly with values from a dataset you already have. That is what I gave you. There is NO word there about writing a file. Please make up your mind BEFORE posting a question.
@SASSLICK001 wrote:
sorry I was not clear earlier, I actually wanted to the sas statements to .sas file
You can use CALL EXECUTE to call the macro directly. An older style of programming has a user write the commands to a file and then %INCLUDE the file, but CALL EXECUTE or DOSUBL are newer options that are more efficient since your program is fully dynamic/data driven.
@SASSLICK001 wrote:
sorry I was not clear earlier, I actually wanted to the sas statements to .sas file
Not necessary. See @Reeza's post.
Your variable name does not seem appropriate for the code you are generating, but here you go.
data _null_;
set have ;
file 'myprogram.sas';
put '%run(dataset=' pgmname ');' ;
run;
It would be even easier if the variable was named DATASET to match how you are using it in the generated code.
data _null_;
set have ;
file 'myprogram.sas';
put '%run(' dataset= ');' ;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.