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

Hello!

 

I am using SAS Enterprise Guide 7.1.

 

I am concatenating multiple datasets together, however there isn't a date in any of the datasets, only the title. Is there a way to create a new column per dataset that I am concatenating?

 

My current code without the extra columns is (for visibility I've kept just 3 months that I actually need):

 

data cues;
set
cue_201603 (keep= id cue5 cue8  where=(ID IN (&c1.)));
cue_201604 (keep= id cue5 cue8  where=(ID IN (&c1.)));
cue_201605 (keep= id cue5 cue8  where=(ID IN (&c1.)));
run;

I was hoping there was a way to create a column called month per dataset and have it output 201603, 201604 and 201605, so that it is all under the same column.

 

I also only want to select certain columns to speed it up, so would like to keep the keep statement, and also the where statement, to only select the specific ids in a macro variable.

 

Can this be done?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use the INDSNAME= option of the SET statement.

This is used to name a (temporary) variable that will be populated with the name of the dataset that contributed this observation.  To add a permanent variable copy or transform the value into another variable. It kind of looks like the names have a month embedded in them.

data cues;
  length dsname $41 ;
  set
    cue_201603 (keep= id cue5 cue8  where=(ID IN (&c1.)))
    cue_201604 (keep= id cue5 cue8  where=(ID IN (&c1.)))
    cue_201605 (keep= id cue5 cue8  where=(ID IN (&c1.)))
    indsname=dsname
  ;
  month = input(scan(dsname,2,'_.'),yymmn6.);
  format month yymmn6. ;
run;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Use the INDSNAME= option of the SET statement.

This is used to name a (temporary) variable that will be populated with the name of the dataset that contributed this observation.  To add a permanent variable copy or transform the value into another variable. It kind of looks like the names have a month embedded in them.

data cues;
  length dsname $41 ;
  set
    cue_201603 (keep= id cue5 cue8  where=(ID IN (&c1.)))
    cue_201604 (keep= id cue5 cue8  where=(ID IN (&c1.)))
    cue_201605 (keep= id cue5 cue8  where=(ID IN (&c1.)))
    indsname=dsname
  ;
  month = input(scan(dsname,2,'_.'),yymmn6.);
  format month yymmn6. ;
run;

 

_SASEG_
Calcite | Level 5

Thanks @Tom! Yes, the date is embedded into the file. It worked perfectly!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 552 views
  • 1 like
  • 2 in conversation