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.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 307 views
  • 0 likes
  • 2 in conversation