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

I want to create macro list of variables that contains variables are in the NEW dataset only. NEW and OLD only contain the variable "name," generated from proc contents output.  

 

proc sql ;
select * into :varlist separated " " 
from  new
except  
select * from old;
quit;

If I omit "into :varlist separated " " " I get the list of unique variables in NEW. Using SAS 9.4. Thanks all! 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

A fun test:

 


data new;
input a;
cards;
1
2
3
3
4
4
5
;

data old;
input a;
cards;
1
2
5
;

proc sql ;
select * into :varlist separated " " 
from 
(select *
from  new
except  all
select * from old);
quit;

%put &varlist;

Results:

 

%put &varlist;
3 3 4 4

 

Either way, Please be advised not to use * 

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

You have missed EXCEPT ALL

 

proc sql ;
select * into :varlist separated " " 
from  new
except  all
select * from old;
quit;
novinosrin
Tourmaline | Level 20

A fun test:

 


data new;
input a;
cards;
1
2
3
3
4
4
5
;

data old;
input a;
cards;
1
2
5
;

proc sql ;
select * into :varlist separated " " 
from 
(select *
from  new
except  all
select * from old);
quit;

%put &varlist;

Results:

 

%put &varlist;
3 3 4 4

 

Either way, Please be advised not to use * 

Tom
Super User Tom
Super User

That works because * expands to just a single variable since the result of the inner query only has one column.

nd
Obsidian | Level 7 nd
Obsidian | Level 7
Thanks, this is a big help!
Tom
Super User Tom
Super User

You cannot select * into a macro variable. You can only select a single expression.

You can only use INTO on the outer most query.

select name into :namelist separated by ' '
from 
(select name from new
  except
  select name from old
)
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @nd 

 

It is not clear what you want. Is it a list of variable names or variable values?, and how should they be separated?

 

Please provide example data for new and old data sets and the expected output (macro variable value)

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
  • 6 replies
  • 2294 views
  • 2 likes
  • 4 in conversation