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

Below code is resolving the values of va and vb but not able to excute input function in below code:

 

data temp;

set tmp(keep=&keep_full_lst.);

array vars {*} a1-a&count.;

do i = 1 to &count.;

va=symget('VARS'||left(i));

vb=symget('VARFMT'||left(i));

put vb;

vars{i} = put(input(va,vb),50.);

end;

drop i va vb;

run;

 

Failing :

ERROR 85-322: Expecting a format name.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

The input() function expects a format name as its second argument, not a character expression that results in a format name. Use the inputn() (or inputc() for character) instead. These functions expect a character expression as second argument.

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

The input() function expects a format name as its second argument, not a character expression that results in a format name. Use the inputn() (or inputc() for character) instead. These functions expect a character expression as second argument.

swwithsas
Fluorite | Level 6

It is not throwing error now but not even displaying any values:

 

data temp;

set tmp(keep=&keep_full_lst.);

array vars {*} a1-a&count.;

do i = 1 to &count.;

va=symget('VARS'||left(i));

vb=symget('VARFMT'||left(i));

put va vb;

 

vars{i} = putc(va,vb);

end;

drop i va vb;

run;

 

All the vars variables are '.'

 

Kurt_Bremser
Super User

You used putc, which creates character values, but did not create the array as character. You will find NOTEs about the conversions and invalid values in the log.

Expand your array statement:

array vars {*} $ 10 a1-a&count.;

You may have to adapt the length.

swwithsas
Fluorite | Level 6

Thanks. Sorry for silly questions. I have another one.

 

data temp;

set tmp(keep=&keep_full_lst.);

array vars {*} $ 50 a1-a&count.;

do i = 1 to &count.;

va=symget('VARS'||left(i));

vb=symget('VARFMT'||left(i));

put va vb;

 

vars{i} = putc(va,vb);

end;

drop i va vb;

run;

 

This worked by adding $ and length, BUT, it should apply format on the column names resolved by "va". It is just printing the va values for each row of the dataset tmp.

Kurt_Bremser
Super User

If you want to asssign formats to columns, you do that in proc datasets, and you need to dynamically create the code for that from your data source that contains the variable-format name/value pairs.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 6664 views
  • 3 likes
  • 2 in conversation