BookmarkSubscribeRSS Feed
antonsvart
Fluorite | Level 6

Hello,

 

I'm trying to use some concatenated informat, format, and input statements that live within a SAS table to function as syntax in a data step. E.g. the following statement 

 

informat patient_id $32. ;

 

is a value of a column called "informatStatement".

 

How would I be able to use these stored values as statements in an actual data step for many other variable (not just patient_id) and many other tables? Or am I going about this all wrong? I'm using base SAS 9.4. Thanks for your help. 

1 REPLY 1
ed_sas_member
Meteorite | Level 14

Hi @antonsvart 

 

You can use the PROC DATASETS (link) to do this kind of manipulation, including:

  • modifying SAS files
  • labeling a SAS data set
  • adding a Read password to a SAS data set
  • indicating how a SAS data set is currently sorted
  • creating an index for a SAS data set
  • assigning informats and formats to variables in a SAS data set -> your use case.
  • renaming variables in a SAS data set
  • labeling variables in a SAS data set

e.g.

proc datasets lib=work;
	modify mydata;
	informat patient_id $32.;
run;

If you have these statements stored in a dataset, you can use the DOSUBL() function or the CALL EXECUTE :

 

data have;
	InformatStatement = 'informat patient_id $32. ;'; output;
	InformatStatement = 'informat date date9. ;'; output;
run;

data _null_;
	set have;
	rc = dosubl(cats('proc datasets lib=work; modify mydata; ',informatStatement,'; run;'));
run;

NB: replace 'mydata' by your dataset name in the modify statement.

-> this will execute the proc datasets at each iteration according to the value of the 'InformationStatement' variable in the 'have' dataset.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 400 views
  • 0 likes
  • 2 in conversation