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.