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

Hello! I used proc sql; in my code and I was wondering how can I do a short spelling of this?

Harkonnen_0-1612345899659.png

In a data step, it will be v1-v11, but what syntaxis will be correct for SQL?

 

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

PROC SQL does not handle variable lists. You can do this with a macro or through meta data, but it will not be shorter.

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

PROC SQL does not handle variable lists. You can do this with a macro or through meta data, but it will not be shorter.

FreelanceReinh
Jade | Level 19

Hello @Harkonnen,

 

In PROC SQL you can use "select *" in conjunction with KEEP= and DROP= dataset options, which support variable lists. However, you would need to check on a case-by-case basis whether an intended query can be simplified by this approach. Here's an example:

 

/* Create test data for demonstration */

data tab_aval_rdy;
array a[*] or_p or_v or_s v1-v20 (1:23);
output;
call stdize(of a[*]);
output;
run;

data tab_chg_rdy;
array b[*] or_p or_v or_s x y z (1:6);
output;
output;
run;

/* Use "*" and variable lists in dataset options in the query */

proc sql;
create table full_tab(keep=v:) as
select a.*
from tab_aval_rdy(keep=v1-v11 or:) a left join tab_chg_rdy b
on a.or_p=b.or_p and a.or_v=b.or_v and a.or_s=b.or_s;
quit;

The same result would be obtained with the code shown in your screenshot. In this example the dataset option keep=v1-v11 or: could also be replaced by drop=v12-v20.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 489 views
  • 3 likes
  • 3 in conversation