BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chingweelim
Calcite | Level 5

I have a few proc format values which I want to use in the second argument of put(source,format). For example:

proc format library = work ;
    value GROUP
	0 = 'Controlled Hypertensive Patients'
	1 = 'Uncontrolled Hypertensive Patients';


    value COUNTRY
        0 = 'CHINA'
        1 = 'BRITAIN'
        2 = 'USA';
run;

I plan to use them in a do loop in data step. So lets say I have a dataset called 'have' that contains variables 'GROUP' and 'COUNTRY' (same names as the value formats). This is what I tried:

 

%let var_format=GROUP COUNTRY

data want;
set have;
format Variable_label $150.;
do _i=1 to countw(symget('var_format'));
    Variable_label = put( scan(symget('var_format'),_i) , scan(symget('var_format'),_i). ); end; drop _:; run;

Unfortunately, in the second argument of the put(source,format) statement, it gave the following error in the log:

 

Variable_label = put(scan(symget('var_format'),_i),scan(symget('var_format'),_i).);
                                                   ----
                                                    85
                                                    76
ERROR 85-322: Expecting a format name.

ERROR 76-322: Syntax error, statement will be ignored.

As such, is there anyway around this problem?

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

PUT function requires a format as second argument. (See error message)

Format should end with a dot and optionally length, so you need define:

%let var_format=GROUP COUNTRY. ;

 

You can use function PUTC (PUTN for numeric ) with next syntax:

   

PUTC(source, format.<,w>) 

and I would assign a temporary variable:

      _varx = symget('var_format');

and replace all symget('var_format') with the _varx.

 

 

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

PUT function requires a format as second argument. (See error message)

Format should end with a dot and optionally length, so you need define:

%let var_format=GROUP COUNTRY. ;

 

You can use function PUTC (PUTN for numeric ) with next syntax:

   

PUTC(source, format.<,w>) 

and I would assign a temporary variable:

      _varx = symget('var_format');

and replace all symget('var_format') with the _varx.

 

 

Reeza
Super User

PUTC and PUTN will take a text argument for the second parameter so you don’t need this macro implementation. 

At lear

chingweelim
Calcite | Level 5

Hi Reeza and Shmuel,

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1331 views
  • 0 likes
  • 3 in conversation