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.
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.
@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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: