BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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;
3 REPLIES 3
Tom
Super User Tom
Super User

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;

 

Reeza
Super User
I would suggest creating a format using a data set and then using CNTLIN within PROC FORMAT. There's a paper called not just another pretty face - proc format that's a great reference for understanding how to create a format.
Otherwise you could consider having a partial format.

If you really want that to work, use %SCAN() or wrap it in %SYSFUNC()
ballardw
Super User

@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.

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1134 views
  • 2 likes
  • 4 in conversation