BookmarkSubscribeRSS Feed
huongtruong
Calcite | Level 5

Hi All,

I encounter some difficulties in processing a bunch of data. I would like to import all files in the folder into SAS. Could anyone help me on this. I have attached four files: the first three files are examples I have to import and the last file is the report I would like to generate.

There are some steps I have to do:

1. Only include information of Institutional Ownership, starting from the observation 30th.

=> I think of using FIRSTOBS function in PROC IMPORT

Also, the last paragraph (after institutional ownership) should be excluded

=> I think of using MISSING function of more than two cells then delete

2. Need to rename all the variable => since when importing in SAS, it will automatically changes the name to VAR

3. To create the PERIOD column in the FINAL_RESULT

=> I use the PROC TRANSPOSE => need to reformat the DATE in  POSITION column

4. Create the COMPANY NAME => don't have any idea yet on this.

Can anyone help me on this? Any suggestion is greatly appreciated! Thanks

Best Regards,

Helen.

3 REPLIES 3
esjackso
Quartz | Level 8

Here is some code to get all the excel filenames in a folder in a dataset. The readin might be a little different depending on whether this is a one time task or has to be repeated over and over again.

Data xlsx_file ;

  length file_name $200 ;

     rc = filename("dir","FOLDER PATH HERE");

     d = dopen("dir");

     n = dnum(d);

  do i = 1 to n;

          file_name = dread(d,i);

  if lowcase(scan(file_name,2,'.')) = 'xls' then output;

  end;   

run;

huongtruong
Calcite | Level 5

Hi Esjackso1,

Do you know how to import all the files (in the same folder) to SAS, rather than import individually?

Thanks!

Cheers,

Helen.

Doc_Duke
Rhodochrosite | Level 12

Helen,

This question has been asked before.  Go to the main SAS Communities page

and search for

import directory

You'll find an number of approaches.

Also, this particular forum is intended for help with the forum itself.  Your future posts might get more answers if they are in the data step or procedures forums (depending on the question).

Doc Muhlbaier

Duke

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 904 views
  • 0 likes
  • 3 in conversation