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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 815 views
  • 1 like
  • 2 in conversation