BookmarkSubscribeRSS Feed
maf9
Calcite | Level 5

I've imported two datasets from excel ('Current_IC' and 'Current_EC') and want to combine the two datasets to create a new table called CurrentData.  The issue is that I've defined a variable, 'Combined', that will take on the values 'Both', 'IC', or 'EC'.  If the variable = 'Both' then i want to combine the two datasets.  If it's 'IC' I only want to put in 'Current_IC' to the CurrentData table, and if it's 'EC' then I only want to add 'Current_EC'.  I don't know how to add an if statement to accomplish this.  Below is the code I have to combine the two sets but how do I add an if statement?

 

Data CurrentData;

Set Current_IC Current_EC;

Run;

 

If the variable 'Combined' = IC then the code would be

 

Data CurrentData;

Set Current_IC;

Run;

 

Any help with this would be great.

1 REPLY 1
collinelliot
Barite | Level 11

 

You can name multiple data sets in the data statement and output them conditionally based on the value of your Combined variable;

 

Something like this:

data combo ic_only ec_only;   
 set current_ic current_ec;   
 if combined = 'Both' then output combo;   
 else if combined = 'IC' then output ic_only;   
 else if combined = 'EC' then output ec_only;
run;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 582 views
  • 0 likes
  • 2 in conversation