I want to retain column names in the alphabetical order. I already have another table which has a single column consisting of these names in alphabetical order. Can I somehow incorporate this into the retain statement instead of typing all the column names manually?
@aalluru wrote:
I'm getting an error for each column saying:
ERROR: Alphabetic prefixes for enumerated variables (<column name>) are different.
This is how SAS punishes people who insist on using non-standard variable names. ;-)
The NLITERAL function should resolve the issue, though:
select nliteral(name) into :names separated by " "
proc sql noprint;
select name into :names separated by " "
from dictionary.columns
where libname = "LIBNAME" and memname = "DSNAME"
order by name;
quit;
data want;
retain &names.;
set libname.dsname;
run;
@aalluru wrote:
I already have another table which has a single column consisting of these names in alphabetical order. Can I somehow incorporate this into the retain statement instead of typing all the column names manually?
Yes, in Kurt_Bremser's code replace
dictionary.columns where libname = "LIBNAME" and memname = "DSNAME"
with the name of that other table and replace "name" with the name of its single column.
Alternatively, you could use CALL SYMPUTX in a data step to write the variable names from that table (concatenated with the CATX function) into macro variable names.
I'm getting an error for each column saying:
ERROR: Alphabetic prefixes for enumerated variables (<column name>) are different.
@aalluru wrote:
I'm getting an error for each column saying:
ERROR: Alphabetic prefixes for enumerated variables (<column name>) are different.
This is how SAS punishes people who insist on using non-standard variable names. ;-)
The NLITERAL function should resolve the issue, though:
select nliteral(name) into :names separated by " "
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.