I need to read daily supplied json files on a dynamic way eg. name of datafile is data_20201016_system.json - the numbers is the date of the current day.
How can I in a simple way load these files ?
I use SAS DI or SAS EG.
I have tried the libname but it fails.
Thanks in advance.
my code is here:
%let dato_d=%sysfunc(putn(%eval(%sysfunc(today())-3),yymmddn8.));
%put &dato_d;
libname IN json '\\DW\Data\data_"&dato_d."_system.json' map='user.map' automap=create;
libname out '\\DW\Dataout';
data out.data_"&dato_d"_system;
set IN.ROOT;
run;
log
4312 libname IN json
4312 ! '\\DW\data\data_"&dato_d."_system.json'
4312 ! map='user.map' automap=create;
ERROR: Invalid physical name.
ERROR: Error in the LIBNAME statement.
4313
4314 libname out '\\DW\Dataout';
NOTE: Libref OUT was successfully assigned as follows:
163 The SAS System 17:12 Friday, October 16, 2020
Engine: V9
Physical Name: \\\\DW\Dataout
4315
4316 data out.data_"&dato_d"_system;
NOTE: Line generated by the macro variable "DATO_D".
4316 "20201013
_________
49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
4317 set IN.ROOT;
ERROR: Libref IN is not assigned.
4318 run;
ERROR: The value '20201013'n is not a valid SAS name.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set OUT.DATA_ may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set OUT.DATA_ was not replaced because this step was stopped.
libname IN json "\\DW\Data\data_&dato_d._system.json" map='user.map' automap=create;
Remove the inside double quotes and change the outer ones to double from single.
That should work for you now.
@ANLYNG wrote:
I need to read daily supplied json files on a dynamic way eg. name of datafile is data_20201016_system.json - the numbers is the date of the current day.
How can I in a simple way load these files ?
I use SAS DI or SAS EG.
I have tried the libname but it fails.
Thanks in advance.
my code is here:
%let dato_d=%sysfunc(putn(%eval(%sysfunc(today())-3),yymmddn8.));
%put &dato_d;
libname IN json '\\DW\Data\data_"&dato_d."_system.json' map='user.map' automap=create;libname out '\\DW\Dataout';
data out.data_"&dato_d"_system;
set IN.ROOT;
run;
log
4312 libname IN json
4312 ! '\\DW\data\data_"&dato_d."_system.json'
4312 ! map='user.map' automap=create;
ERROR: Invalid physical name.
ERROR: Error in the LIBNAME statement.
4313
4314 libname out '\\DW\Dataout';
NOTE: Libref OUT was successfully assigned as follows:
163 The SAS System 17:12 Friday, October 16, 2020Engine: V9
Physical Name: \\\\DW\Dataout
4315
4316 data out.data_"&dato_d"_system;
NOTE: Line generated by the macro variable "DATO_D".
4316 "20201013
_________
49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.4317 set IN.ROOT;
ERROR: Libref IN is not assigned.
4318 run;ERROR: The value '20201013'n is not a valid SAS name.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set OUT.DATA_ may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set OUT.DATA_ was not replaced because this step was stopped.
libname IN json "\\DW\Data\data_&dato_d._system.json" map='user.map' automap=create;
Remove the inside double quotes and change the outer ones to double from single.
That should work for you now.
@ANLYNG wrote:
I need to read daily supplied json files on a dynamic way eg. name of datafile is data_20201016_system.json - the numbers is the date of the current day.
How can I in a simple way load these files ?
I use SAS DI or SAS EG.
I have tried the libname but it fails.
Thanks in advance.
my code is here:
%let dato_d=%sysfunc(putn(%eval(%sysfunc(today())-3),yymmddn8.));
%put &dato_d;
libname IN json '\\DW\Data\data_"&dato_d."_system.json' map='user.map' automap=create;libname out '\\DW\Dataout';
data out.data_"&dato_d"_system;
set IN.ROOT;
run;
log
4312 libname IN json
4312 ! '\\DW\data\data_"&dato_d."_system.json'
4312 ! map='user.map' automap=create;
ERROR: Invalid physical name.
ERROR: Error in the LIBNAME statement.
4313
4314 libname out '\\DW\Dataout';
NOTE: Libref OUT was successfully assigned as follows:
163 The SAS System 17:12 Friday, October 16, 2020Engine: V9
Physical Name: \\\\DW\Dataout
4315
4316 data out.data_"&dato_d"_system;
NOTE: Line generated by the macro variable "DATO_D".
4316 "20201013
_________
49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.4317 set IN.ROOT;
ERROR: Libref IN is not assigned.
4318 run;ERROR: The value '20201013'n is not a valid SAS name.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set OUT.DATA_ may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set OUT.DATA_ was not replaced because this step was stopped.
@Reeza wrote:
%let dato_d = %sysfunc( today() - 3, yymmddn8.);
That is not going to work. The TODAY() function needs to be wrapped in %SYSFUNC().
You could use the second argument to %SYSFUNC() to reference a format, but you cannot also do the subtraction. So you could do:
%let dato_d = %sysfunc( today() , yymmddn8.);
But to subtract the 3 days you need to do more. So you could use PUTN() to format the result of subtracting 3.
And you can do that without an explicit call to %EVAL() when it is in the argument passed to the PUTN() function.
%let dato_d = %sysfunc(putn( %sysfunc(today()) - 3, yymmddn8.));
Just remove the random quotes. Only put the quotes where the SAS syntax needs them.
Also you don't need the %EVAL() as %sysfunc() will evaluate normal SAS expressions.
%let dato_d=%sysfunc(putn(%sysfunc(today())-3,yymmddn8.));
%put &=dato_d;
libname IN json "\\DW\Data\data_&dato_d._system.json"
map='user.map' automap=create
;
libname out '\\DW\Dataout';
data out.data_&dato_d._system;
set IN.ROOT;
run;
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 25. 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.