Hi All,
Folder Question:
folder path = [path]\folder_YYYYMMDD;
I just like to know how to use folder starts with
libname "[path]\folder_*";
File Question:
file name = [path]\filename_xxxxxx;
proc export data=Pred_All_Region1_final
outfile="[path]\filename_*"
dbms=csv replace;
run;
I like to know how to read a folder or file starts with a name
Any help would be appreciated
Describe what you mean by "read a folder"?
If you mean "read every file in a folder" that is one thing but "read a folder" isn't obvious.
You say read a file and then show proc Export?
Proc IMPORT will attempt to read multiple files when you use something like:
proc import datafile = "X:\Data\IPP\Data\Text data\2018\ada*" out=work.junk dbms=CSV replace ; run;
Which will "read" all of the files in the folder that start with ADA in the name. However my folder has a mix of CSV and XLSX files and attempts to read both. It creates a data set without an error BUT there is binary data not actual values.
If I restrict it to
proc import datafile = "X:\Data\IPP\Data\Text data\2018\ada*.CSV" out=work.junk dbms=CSV replace ; run;
The result makes somewhat more sense but every single variable is character because the header row with the variable names is treated as character when read multiple times (the files have few rows).
So describe what you actually want to do in a bit more detail and what you expect the results to be.
Describe what you mean by "read a folder"?
If you mean "read every file in a folder" that is one thing but "read a folder" isn't obvious.
You say read a file and then show proc Export?
Proc IMPORT will attempt to read multiple files when you use something like:
proc import datafile = "X:\Data\IPP\Data\Text data\2018\ada*" out=work.junk dbms=CSV replace ; run;
Which will "read" all of the files in the folder that start with ADA in the name. However my folder has a mix of CSV and XLSX files and attempts to read both. It creates a data set without an error BUT there is binary data not actual values.
If I restrict it to
proc import datafile = "X:\Data\IPP\Data\Text data\2018\ada*.CSV" out=work.junk dbms=CSV replace ; run;
The result makes somewhat more sense but every single variable is character because the header row with the variable names is treated as character when read multiple times (the files have few rows).
So describe what you actually want to do in a bit more detail and what you expect the results to be.
Thanks I thought * wont work 🙂 @ballardw
I have several programs that read multiple files, partially because I get replacements and need to make sure that I have the latest data.
The start of one of them looks like this
data output ; infile "x:\data\IPP\data\Text Data\2018\IDEX*.DAT" delimiter='09'x DSD lrecl=32767 firstobs=2 eov=skip missover;
because with a data step I get to do things like skip the first row in the intermediate files. The EOV option creates a variable that has value of 1 when the first record of a new set is encountered. Which means I can test that value and do things needed for the next file, like skip reading the header row in the middle of a data stream. I also get to test if some of the data content changes in an expected manner.
Don't be afraid to try the occasional bit of odd syntax. Just make sure that anything that might be taken as an output data set name doesn't reference data you don't mind losing if something unexpected happens.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.