So I have to do the exact same thing over and over again for multiple dataset, so I figured a macro might be helpful. This is the code I am trying to run.
%macro lab (fich, num);
data &fich;
set &fich;
if CRF&num=" " then CRF&num="MISSING";
%let &num=%eval(&num+1);
if CRF&num=" " then CRF&num="MISSING";
run;
%mend lab;
%lab(temp,55);
%lab(temp1,60);
So basically, I have variables (CRF55, CRF56, CRF57..and so on) that I want it to insert the word "MISSING" when the character value is blank. And then the same thing again for another dataset starting with var CRF60 (so this case will be CRF60, CRF61, CRF62 and so on). I have to do this for 4 varaibles per dataset and all in numerical order (e.g 55,56,57,58 and then another dataset for 60,61,62,63...etc.)
Can someone suggests an easy way to do this without manually coding every dataset?
The only other solution I can think of is create multiple datasteps and do the %let statement to change the num inbetween each datasets. but I feel there is a more efficient way to code this.
%macro lab (fich, num);
data &fich;
set &fich;
if CRF&num=" " then CRF&num="MISSING";
run;
%let &num=%eval(&num+1);
data &fich;
set &fich;
if CRF&num=" " then CRF&num="MISSING";
run;
%mend lab;
Thank you!!!
Your better off looking at arrays:
data want;
set have;
array crf{*} _character_;
do i=1 to dim(crf);
if crf{i}="" then crf{i}="Missing";
end
run;
Your better off looking at arrays:
data want;
set have;
array crf{*} _character_;
do i=1 to dim(crf);
if crf{i}="" then crf{i}="Missing";
end
run;
To add to RW9 you can also list specific variables instead of all character variables.
array crf{*} crf55 crf56 crf57;
or a variable list
array crf{*} crf55 - crf59;
Why not just use a format instead of modifying the data?
proc format ; value $miss ' '='Missing'; run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.