DATA Step, Macro, Functions and more

Insert text into all cells of first column in a sas dataset

Reply
Regular Contributor
Posts: 223

Insert text into all cells of first column in a sas dataset

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

 

 

Super User
Posts: 19,770

Re: Insert text into all cells of first column in a sas dataset

Posted in reply to NicholasKormanik

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;
Super User
Posts: 5,497

Re: Insert text into all cells of first column in a sas dataset

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.

Super User
Super User
Posts: 7,942

Re: Insert text into all cells of first column in a sas dataset

Posted in reply to NicholasKormanik

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.

Ask a Question
Discussion stats
  • 3 replies
  • 201 views
  • 0 likes
  • 4 in conversation