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.
Hi @antonsvart
You can use the PROC DATASETS (link) to do this kind of manipulation, including:
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.