DATA Step, Macro, Functions and more

Filename Statement

Accepted Solution Solved
Reply
Contributor
Posts: 45
Accepted Solution

Filename Statement

How do I make a small sample raw data (txt) file on my desktop and read it into SAS Studio using a FILENAME statement and the COLUMN INPUT METHOD?

 

For example, this is the raw data file (txt). I named it as joytp and I placed the file on my desktop. I want to read into SAS Studio:

 

2810 61 MOD  F

2804 38 HIGH F

2807 42 LOW  M

2816 26 HIGH M

2833 32 MOD  F

2823 29 HIGH F

 

 

Can anyone tell me the code that I have to write before the below lines inorder to read the txt file above into SAS Studio:

 

input ID $ 1-4 Age 6-7 Actlevel $ 9-12 Sex $ 14;

run;


Accepted Solutions
Solution
‎08-20-2016 11:48 AM
SAS Super FREQ
Posts: 8,745

Re: Filename Statement

Hi:
You only mention a filename (joytp.txt), but you did not mention whether you put the file in your shared folder location. In order to read the file, you would need to either do this:

INFILE '/folders/myfolders/joytp.txt';
OR

FILENAME mytxt '/folders/myfolders/joytp.txt';

then
INFILE mytxt;
INPUT ..... ..... ;

But, this all hinges on whether you put the .TXT file into your shared folder location. Can you see the file when you are inside SAS Studio? If so, you should be able to right click on the file name, choose Properties and see the path location to use in either your FILENAME or your INFILE statement. The Location information in the Properties window will show you the fully qualified location that you need to just copy and paste into your code.

Of course, if you do not see JOYTP.TXT in your SAS Studio files, then you will need to move it into your shared folder location or a location where you know that SAS University Edition can read. Just remember that SAS University Edition in a Virtual Machine will NOT use C: drive locations.

cynthia

View solution in original post


All Replies
Super User
Posts: 17,963

Re: Filename Statement

Are you using SAS University Edition?

Contributor
Posts: 45

Re: Filename Statement

Yes, Univ Edition. Thanks.
Solution
‎08-20-2016 11:48 AM
SAS Super FREQ
Posts: 8,745

Re: Filename Statement

Hi:
You only mention a filename (joytp.txt), but you did not mention whether you put the file in your shared folder location. In order to read the file, you would need to either do this:

INFILE '/folders/myfolders/joytp.txt';
OR

FILENAME mytxt '/folders/myfolders/joytp.txt';

then
INFILE mytxt;
INPUT ..... ..... ;

But, this all hinges on whether you put the .TXT file into your shared folder location. Can you see the file when you are inside SAS Studio? If so, you should be able to right click on the file name, choose Properties and see the path location to use in either your FILENAME or your INFILE statement. The Location information in the Properties window will show you the fully qualified location that you need to just copy and paste into your code.

Of course, if you do not see JOYTP.TXT in your SAS Studio files, then you will need to move it into your shared folder location or a location where you know that SAS University Edition can read. Just remember that SAS University Edition in a Virtual Machine will NOT use C: drive locations.

cynthia
Contributor
Posts: 45

Re: Filename Statement

Ah! Got it, Thank you so much, been struggling with this since an hour. I moved the file to the University Edition shared folder and followed your steps! Thanks!
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 355 views
  • 2 likes
  • 3 in conversation