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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

sidpesar
Obsidian | Level 7

Thanks I thought * wont work 🙂 @ballardw 

ballardw
Super User

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.

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