BookmarkSubscribeRSS Feed
NKormanik
Barite | Level 11

I've output 'Moments' from Proc Univariate to datasets.  Many.

 

Example:  Moments_001.sas7bdat through to Moments_237.sas7bdat

 

For the first column of each dataset (new added first column, and probably new dataset, as opposed to the original) I would like to have a particular text in every cell going down to bottom row.

 

The exact text would be the name of the respective dataset file: say, "Moments_001".

 

I do not have to 'grab' the filename, per se, if that's not possible.  As I know what the names are already, I can put that text into the procedure.  However, grabbing the filenames, if possible, would be easier from my standpoint.

 

I'd greatly appreciate any help anyone could provide to accomplish this.

 

Thanks,

Nicholas Kormanik

 

 

3 REPLIES 3
Reeza
Super User

There's the INDSNAME option. 

 

Are you you planning to append the files? If so, something like the following should work. 

 

Data moments_all;
Set moments_1 - moments_237 indsname=source;

Dataset_source = source;
Run;
Astounding
PROC Star

To make your new variable appear as the first column, also add a LENGTH statement:

 

data moments_all;

length dataset_source $ 32;

set moments_1 - moments_237 indsname=source; 

dataset_source = source; 

run;

 

The LENGTH statement must come before the SET statement for this to work properly.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why have you created hundreds of datasets?  One of the prime benefits of SAS is that it allows you to process datasets using by groups - hence one dataset can contain many by groups.  This is both faster (open file once), and far simpler to work with.  My suggestion is to look at the process up to an including the univariate, and fix that so you have one dataset to work with.

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
  • 3 replies
  • 1154 views
  • 0 likes
  • 4 in conversation