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

Hello,

I need to save SAS files locally so others can access them (it cannot be saved in my SAS library). This is data being extracted from REDCap. With each one of my weekly data extractions I create multiple SAS files (A1 A2 A3 etc) that must be merged weekly, to create a database to be used in a code that compares new records with old ones for issues. 
My code to call and merge these files only works for the latest created file, in this case A5, it tells me files 1 to 4 do not exist. Files I have saved in my computer in previous weeks.
What am I missing?
Libname CHECK 'C:my desktop folder where the SAS files (A1 to A5) are';
%macro combine;
data want;
  set
  %do i = 1 %to 5;  
    A&i
  %end;
  ;
run;
 
%mend;
 
%combine;
**********************************
I appreciate your help.
 
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you reference a dataset using a single name like A1 or A2 then it will look for WORK.A1 or WORK.A2.  WORK datasets are removed when your SAS session ends.

 

If you want to instead find CHECK.A1 then say so in the SAS code you ask the macro processor to generate.

 

Note if you just want to check a set of datasets that end with a sequence of integers then there is no need for macro code.  You can use a list of dataset names instead like this:

data want;
  set check.a1 - check.a2;
run;

 

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

..in this case A5, it tells me files 1 to 4 do not exist

 

Do not paraphrase the messages. We need the exact word-for-word message. The best way is to show us the ENTIRE log from running this macro.

 

Please run this command first, to turn on macro debugging.

 

options mprint;

 

Then run your macro, and paste the log into the window that appears when you click on the </> icon. Do not skip this step.

PaigeMiller_0-1699900743276.png

 

And from now on, if you get errors, please do show us the log. Don't wait until we ask.

--
Paige Miller
Mscarboncopy
Pyrite | Level 9

This is what my log shows. The issue seems to be that the macro code is searching for the files in my SAS library but they are not there. How do I change this code to look for these files A1 A2 A3 A4 A5 in my desktop? Maybe there isn't a way.

 

 options mprint;
15198  %macro combine;
15199
15200
15201  data ALL;
15202    set
15203    %do i = 1 %to 5;
15204      A&i
15205    %end;
15206    ;
15207  run;
15208
15209  %mend;
15210
15211  %combine;
MPRINT(COMBINE):   data ALL;
MPRINT(COMBINE):   set A1 A2 A3 A4 A5 ;
ERROR: File MYSAS.A1.DATA does not exist.
ERROR: File MYSAS.A2.DATA does not exist.
ERROR: File MYSAS.A3.DATA does not exist.
ERROR: File MYSAS.A4.DATA does not exist.
MPRINT(COMBINE):   run;
 
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set MYSAS.ALL may be incomplete.  When this step was stopped there were 0
         observations and 16 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
 
Tom
Super User Tom
Super User

For that code to generate those messages you must have set the system option USER to the value MYSAS.

 

It used to be if you defined a libref named USER then single names dataset references, like the A1 and A2 in your code, would reference USER.A1 and USER.A2 instead of the normal WORK.A1 and WORK.A2.  At some point in the last 20 years or so SAS added the USER system option where you could name a different libref instead.

 

You original code was making a libref named CHECK.  But I did not see any code to make a libref named MYSAS.

Mscarboncopy
Pyrite | Level 9

The code for mysas was not shared. Between the first question in the thread from @paige2 thank you!  and your answer, I figured out the issue was exactly what you mentioned. I was not aware I could call files the way you showed me. Thank you so much @Tom 

Tom
Super User Tom
Super User

If you reference a dataset using a single name like A1 or A2 then it will look for WORK.A1 or WORK.A2.  WORK datasets are removed when your SAS session ends.

 

If you want to instead find CHECK.A1 then say so in the SAS code you ask the macro processor to generate.

 

Note if you just want to check a set of datasets that end with a sequence of integers then there is no need for macro code.  You can use a list of dataset names instead like this:

data want;
  set check.a1 - check.a2;
run;

 

Mscarboncopy
Pyrite | Level 9

@Tom

Thank you!! That works.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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
  • 6 replies
  • 521 views
  • 1 like
  • 3 in conversation