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

So this is a general question about how SAS works. Basically if I am trying to stack a bunch of files together but there are some that are missing why does SAS throw an error and not proceed with the command?
For example

data CombinedA;

set A1-A900;

run;

 

Let's say you were missing some files in there like... A89, A401, A589, A623, etc...

 

SAS will throw an error saying those files don't exist but the "CombinedA" file also does not get created.

 

Is there a way to bypass this issue so that SAS will still stack all existing files together? I understand that yes I could just type in ranges and skip over the missing files but that can become tedious.

1 ACCEPTED SOLUTION
6 REPLIES 6
PaigeMiller
Diamond | Level 26

If all the data sets begin with the letter A, then you could use

 

data combinedA;
    set a:;
run;

But this may include other data sets that begin with the letter a that you don't want ... but since you gave us no additional information, that's all we can say at this time.

--
Paige Miller
Leon27607
Fluorite | Level 6
Your method would definitely create some issues, but basically if you need additional information...(I didn't think it would be needed because my question seems pretty simple). I was basically running proc mixed, generating residuals for each variable, and testing for normality using the ODS output "TestsForNormality." Since I have ~800 variables/simple models to run I wanted to stack these tables all together. The problem I ran into was... some of these didn't exist because there was a lack of variation. Hence why I had this question.

I tried to stack 800+ files together, had errors thrown saying some files were missing, SAS wouldn't generate the table with them all stacked together.
PaigeMiller
Diamond | Level 26

@Leon27607 wrote:
Your method would definitely create some issues, but basically if you need additional information...(I didn't think it would be needed because my question seems pretty simple). I was basically running proc mixed, generating residuals for each variable, and testing for normality using the ODS output "TestsForNormality." Since I have ~800 variables/simple models to run I wanted to stack these tables all together. The problem I ran into was... some of these didn't exist because there was a lack of variation. Hence why I had this question.

I tried to stack 800+ files together, had errors thrown saying some files were missing, SAS wouldn't generate the table with them all stacked together.

But it does work if the data set names all have a unique prefix, such as MIXEDOUT1, MIXEDOUT2, MIXEDOUT9, etc. This is something you can control when you create the data sets. Then there are no issues with pulling in unwanted data sets.

 

The only reason I brought up the problem with using data set names that begin with A was because that was the example you gave. I can't generalize to other examples without you providing additional information.

--
Paige Miller
Leon27607
Fluorite | Level 6
Thanks, this worked and basically answered what I was looking for.
Kow
Obsidian | Level 7 Kow
Obsidian | Level 7

You can do a test to see if the dataset exists and conditionally execute based on the result.

 

One advantage to this over the other methods suggested is that you could explicitly report which data sets are missing.

 

But the other answers seem easier if this is not a concern.

 

http://support.sas.com/kb/24/670.html

 

%macro checkds(dsn);
   %if %sysfunc(exist(&dsn)) %then %do;
      proc print data = &dsn;
      run;
   %end;
   %else %do;
      data _null_;
         file print;
         put #3 @10 "Data set &dsn. does not exist";
      run;
   %end;
%mend checkds;

 

 

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
  • 6 replies
  • 902 views
  • 2 likes
  • 4 in conversation