BookmarkSubscribeRSS Feed
SASSLICK001
Obsidian | Level 7

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!

7 REPLIES 7
Kurt_Bremser
Super User

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
Obsidian | Level 7
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
Kurt_Bremser
Super User

@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
Obsidian | Level 7
sorry I was not clear earlier, I actually wanted to the sas statements to .sas file
Reeza
Super User

@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. 

Tom
Super User Tom
Super User

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1327 views
  • 0 likes
  • 4 in conversation