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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Yes. But not with SQL.

The SAS equivalent of your SQL code is:

proc print data=table ;
  var var1-var10 ;
run;

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

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. 

runrunbunny
Obsidian | Level 7
Thank you so much!
Tom
Super User Tom
Super User

Yes. But not with SQL.

The SAS equivalent of your SQL code is:

proc print data=table ;
  var var1-var10 ;
run;
FreelanceReinh
Jade | Level 19

Hi @runrunbunny,

 

In your particular example you could use a dataset option:

proc sql;
select *
from table(keep=var1-var10);
quit;
runrunbunny
Obsidian | Level 7
Good point! Thank you so much!
ChrisNZ
Tourmaline | Level 20

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);

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 3399 views
  • 4 likes
  • 5 in conversation