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

Hi Folks

I am working on a small automation of manual testing in SAS ,we primarily take data sets from different directories and validate the field in the data sets.


so ihave taken two libraries in one sas code for example

libname in1 "/path1"
libname in2 "/path2"

and saved them in test.sas and saved them in output library

my output datasets in libraries will in the following format
1)test021318
2)testa021318
3)testb021318

in all libraries in1,in2 the names of datasets will be same but only paths will differ .


so to make the testing process bit easier and generic i have written a small snippet like this



%include "/path/output/" ;----where libraries are stored in one file

 

%let x = %sysfunc(cats(test,%sysfunc(intnx(day,%sysfunc(today()),-1),mmddyy6.)));
%let y = %sysfunc(cats(testa,%sysfunc(intnx(day,%sysfunc(today()),-1),mmddyy6.)));
%let z = %sysfunc(cats(testb,%sysfunc(intnx(day,%sysfunc(today()),-1),mmddyy6.)));


libname out "/path/output/";

%put &x &y &z;

data out.final;
set in1.&x in1.&y in1.&z
in2.&x in2.&y in2.&z
;
run;

proc print data=out.final;
run;

but my output is printing like this

ERROR: File IN1.test21318.DATA does not exist.
ERROR: File IN1.testa21318.DATA does not exist.
ERROR: File IN1.testb21318.DATA does not exist.
ERROR: File IN2.test21318.DATA does not exist.
ERROR: File IN2.testa21318.DATA does not exist.
ERROR: File IN2.testb21318.DATA does not exist.

 

but in actual output locations datasets will be in the following format

test021318.sas7bdat
testa021318.sas7bdat
testb021318.sas7bdat

 

dataset will be with previous day


could you kindly help me in achieving the desired result.

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19
%let x = %sysfunc(cats(test,%sysfunc(intnx(day,%sysfunc(today()),-1),mmddyy6.)));

This is way to complicated. Using a datastep will result in code that is easier to read and debug:

 

data _null_;
   yesterday = put(today() - 1, mmddyy6.);
   call symputx('x', cats('test', yesterday));
run;

%put &=x;

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19
%let x = %sysfunc(cats(test,%sysfunc(intnx(day,%sysfunc(today()),-1),mmddyy6.)));

This is way to complicated. Using a datastep will result in code that is easier to read and debug:

 

data _null_;
   yesterday = put(today() - 1, mmddyy6.);
   call symputx('x', cats('test', yesterday));
run;

%put &=x;
ashkar
Fluorite | Level 6

Will the dataset always be having name as %sysfunc(today()),-1?

Instead once the libname for in1 and in2 is set, you can use the dictionary.tables to read the dataset names from the library into macro variables and use it in your subsequent datasteps.

 

For instance,

libname in1 "/path1"

 

proc sql;

select memname into :_Dsn1-:_Dsn3

from dictionary.tables where libname = "in1";

quit;

 

%put &_Dsn1;

 

based on the no of datasets you are comparing you can create mv's.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 762 views
  • 2 likes
  • 3 in conversation