DATA Step, Macro, Functions and more

concatenating the data sets with previous day

Accepted Solution Solved
Reply
Highlighted
Occasional Learner
Posts: 1
Accepted Solution

concatenating the data sets with previous day

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.


Accepted Solutions
Solution
‎02-14-2018 06:03 AM
Valued Guide
Posts: 515

Re: concatenating the data sets with previous day

Posted in reply to niteshbharadwaj
%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


All Replies
Solution
‎02-14-2018 06:03 AM
Valued Guide
Posts: 515

Re: concatenating the data sets with previous day

Posted in reply to niteshbharadwaj
%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;
New Contributor
Posts: 4

Re: concatenating the data sets with previous day

Posted in reply to niteshbharadwaj

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.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 90 views
  • 1 like
  • 3 in conversation