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,

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 747 views
  • 0 likes
  • 3 in conversation