Hi,
I would like to select 10 columns(var1 to var10) from a table:
Proc sql;
select var1, var2, var3, var4, var5,var6,var7,var8,var9,var10
from table;
quit;
Is there an convenient way to represent these variables instead of manually listing them?
Thanks a lot!
runrunbunny
Yes. But not with SQL.
The SAS equivalent of your SQL code is:
proc print data=table ;
var var1-var10 ;
run;
Hi @runrunbunny I'm afraid Proc SQL does not support convenient variable lists like that of a datastep. You may have to switch to datastep or read dictionary information aka proc contents aka metadata and assign the variable lists in a macro variable and call the macro variable in SQL.
Thank you so much!
Yes. But not with SQL.
The SAS equivalent of your SQL code is:
proc print data=table ;
var var1-var10 ;
run;
Hi @runrunbunny,
In your particular example you could use a dataset option:
proc sql;
select *
from table(keep=var1-var10);
quit;
SQL doesn't not allow for any shortcut except for the *.
You can use non-SQL options from the SAS language such as
select * from TABLE(keep=VAR1-VAR10);
Calling all data scientists and open-source enthusiasts! Want to solve real problems that impact your company or the world? Register to hack by August 31st!
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.