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 " "
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.