Dear,
I need to create a format from a part of a string using scan function. I am getting errors. Please suggest. Thank you
%let treat1=Placebo + chemotherapy / Placebo;
proc format;
value pcrfmt
1=scan(&treat1.,1,'/')||"Responder"
2=scan(&treat1.,1,'/')||"Non-Responder"
run;
You cannot run data step code inside the middle of statement inside a PROC. You need to use macro code to generate text that SAS will see as code to be run.
proc format;
value pcrfmt
1="%scan(&treat1.,1,/) Responder"
2="%scan(&treat1.,2,/) Non-Responder"
;
run;
You probably do not want those spaces around the / in your TREAT1 macro variable.
%let treat1=Placebo + chemotherapy/Placebo;
If you cannot get rid of them then it might be better to pull the string out first and then use it in the formatted label.
%let treat1=Placebo + chemotherapy / Placebo;
proc format;
value pcrfmt
%let value=%scan(&treat1.,1,/);
1="&value. Responder"
%let value=%scan(&treat1.,2,/);
2="&value. Non-Responder"
;
run;
@knveraraju91 wrote:
Dear,
I need to create a format from a part of a string using scan function. I am getting errors. Please suggest. Thank you
%let treat1=Placebo + chemotherapy / Placebo; proc format; value pcrfmt 1=scan(&treat1.,1,'/')||"Responder" 2=scan(&treat1.,1,'/')||"Non-Responder" run;
May I ask why you need macro code to build this? If the values "Placebo" and "chemotherapy" are coming from somewhere that you aren't sure what they may be and used to create Treat1 perhaps describing that would be the place to start. Is there a list or something that holds the corresponding "responder" and "non-responder" somewhere? Otherwise this appears way more overkill than is warranted by this example.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.