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

%let year1=1950; %let year2=2020;

proc sql; create table comp as
select *
from mydat.abc (keep=gvkey year  IND--BLOCK)
where fyear between &year1 and &year2
order by gvkey, year;
quit;
RUN;

 

My above code works nicely. But I want to make slight changes like the following but it doesn't give me all the variables from IND to Block

%let year1=1950; %let year2=2020;

proc sql; create table comp as
select gvkey, year, IND--BLOCK
from mydat.abc 
where fyear between &year1 and &year2
order by gvkey, year;
quit;
RUN;

Can anyone tell me how should I use IND--BLOCK and get all the variables between IND and BLOCK following the 2nd example? 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Okay I am afraid SQL clauses do not accept variable lists. You would have to use dataset options i.e Keep= or Drop= either in the FROM table or CREATE table. 

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Hi @abdulla  Please try-

%let year1=1950; %let year2=2020;

proc sql; 
create table comp(keep=gvkey year IND--BLOCK) as
select *
from mydat.abc 
where fyear between &year1 and &year2
order by gvkey, year;
quit;
RUN;

/*OR why not in the FROM clause like your example1?*/

%let year1=1950; %let year2=2020;

proc sql; 
create table comp as
select *
from mydat.abc(keep=gvkey year IND--BLOCK)
where fyear between &year1 and &year2
order by gvkey, year;
quit;

 

abdulla
Pyrite | Level 9

Hi novinosrin,
As I showed in my first code, it works. But I don't want to use select*. I want to use select gvkey, year, IND....... Because in my where statement I have the following 

and CONSOL='C'
and INDFMT='INDL'
and DATAFMT='STD'
and POPsrc='D'

If I use the 2nd code, it shows that I don't have the above things

novinosrin
Tourmaline | Level 20

Okay I am afraid SQL clauses do not accept variable lists. You would have to use dataset options i.e Keep= or Drop= either in the FROM table or CREATE table. 

Tom
Super User Tom
Super User

You cannot use variable lists in SQL code. Only in SAS code, like your dataset option.

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!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 912 views
  • 2 likes
  • 3 in conversation