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.
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.
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.
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 '.'
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.
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.
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.