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

I am reading several files into 1 dataset, using a wildcard for the last 8 positions. Now I want to determine these 8 positions, to be also written to my output.

My input files are:

payments_20240110 payments_20240209 payments_20240309 etc ...

So my code is:

data overview;

set payments:;

run;

How do I add a column 'payment_date' to my output? I have been struggling with 'SCAN' function, but I don't get it...

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @WimWeyers and welcome to the SAS Support Communities!

 

The INDSNAME= option of the SET statement stores the dataset name (including the libref, e.g., "WORK") in a temporary variable from which you can extract the date.

 

Example:

data overview;
set payments: indsname=dsn;
payment_date=input(scan(dsn,2,'_'),yymmdd8.);
format payment_date yymmdd10.;
run;

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hello @WimWeyers and welcome to the SAS Support Communities!

 

The INDSNAME= option of the SET statement stores the dataset name (including the libref, e.g., "WORK") in a temporary variable from which you can extract the date.

 

Example:

data overview;
set payments: indsname=dsn;
payment_date=input(scan(dsn,2,'_'),yymmdd8.);
format payment_date yymmdd10.;
run;
ballardw
Super User

Please show the EXACT code that are using to read this with wildcards.

 

If this involves reading external files then the INFILE option FILENAME= would create a temporary variable holding the name of the current file being read and could be parsed.

 

If you are combining data sets by using multiple names of the sets on the SET statement then the INDSNAME= option creates a temporary variable holding the name of the contributing data set that can be parsed.

WimWeyers
Calcite | Level 5
INDSNAME = works perfectly! Thank you both.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 879 views
  • 2 likes
  • 3 in conversation