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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.