DATA Step, Macro, Functions and more

Reading raw files

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Reading raw files

can anyone help me this out and provide me the details? I'm totally lost.

 

thanks


Capture.PNG

Accepted Solutions
Solution
‎04-17-2017 09:49 PM
SAS Super FREQ
Posts: 8,864

Re: Reading raw files

[ Edited ]

Hi:
As Reeza suggests, the ERROR message is accurately telling you what is wrong. You do not have a correct path to your CSV file.

I am not sure you followed ALL the code in the solution. I believe in the actual solution it has:
infile "&path/newemps.csv" dlm=',';

The &PATH is critical. It holds the name of the fully qualified path you are using. Remember in the very first Chapter of the book, the very first demo, you submitted a program to make the data. That program also makes the &PATH helper variable. Here are some examples:
%let path=/folders/myfolders; or
%let path=/folders/myfolders/ecprg013; <-- for SAS University Edition

%let path=c:\workshop\prg1; <-- Windows
%let path=/home/userid/prg1; <-- SAS On Demand

Next, your setup statements were supposed to include the LIBNAME for ORION:
libname orion "&path";

Because the &PATH helper variable is not just there for purposes of the LIBNAME statement, In Programming 1, we also intend for you to use &PATH in the INFILE statement to supply the fully qualified path.

Or, as an alternative, if you made the course files in C:\sas_class\pg1, then you could do this:
infile 'c:\sas_class\pg1\newemps.csv' dlm=',';

But that means every time you use an INFILE statement, you will have to remember and code the exact correct location.

cynthia


View solution in original post


All Replies
SAS Super FREQ
Posts: 8,864

Re: Reading raw files

[ Edited ]

Hi:
   That exercise is from the Programming 1 course, as we teach it in the classroom. The fact that this is a chapter 7 exercise tells me that this is from one of the older versions of the course. In the current version of the course, this exercise is in Chapter 8.

 

  The starter file for the course has the "beginning" statements you need -- if you got the programs that went with that edition of the course. IF you did not get the programs that go with the book, then you'll have to type approximately 7 lines of code.

 

  Here's a hint:
Data ?????;
   length ?????;
   infile ????? dlm=',';
   input ?????;
run;

proc print data=?????;
run;

 If you have the whole book with the exercise, and not just one page, then the solution to the exercise is at the end of the chapter. The Chapter in which this exercise occurs and the previous chapters on INFILE and INPUT and PROC PRINT should have adequate explanation of what all the above statements are for and how they need to be coded.

 

  However, if you are only trying to do the exercise, then here's the explanation:

1) you need a DATA statement to specify the name of the SAS dataset you are creating;

2) you need a LENGTH statement because without any other instructions, the default length of character variables will be 8 characters and the instructions specify you need longer lengths for all of the character variables;

3) you need an INFILE statement to point to the CSV file (you will probably find in the starter program p107e01.sas that the name of the starter file is newemps.csv)

4) you need an INPUT statement to "parse" the raw data lines and turn the raw data into SAS columns and observations

5) you need a RUN; statement as a step boundary to terminate the DATA step program

6) you need a PROC PRINT statement to start the print of the SAS data set you just created. So the name after data= will be the same as the name that appears on your DATA statement in #1

7) if all you want to do is test PROC PRINT, then you need another RUN; as the step boundary for the PROC PRINT step.

 

  If this is homework or you are taking the class from a professor you might want to ask your professor or teaching assistant for more specific help.

cynthia

Occasional Contributor
Posts: 5

Re: Reading raw files

Posted in reply to Cynthia_sas

Hi Cynthia,

 after I run the soulotions:

data work.NewEmployees;

       length First $12 Last $ 18 Title $ 25;

       infile 'newemps.csv' dlm=',';

       input First $ Last $ Title $ Salary;

run;

ERROR: Physical file does not exist, c:\Users\peng\newemps.csv.

 

proc print data=work.NewEmployees;

run;

 

how can i solve this problem?

Super User
Posts: 19,770

Re: Reading raw files

Read the error message. Do you have the text file in that location? If not, where is it? 

You have to include the full path to the CSV file.

Solution
‎04-17-2017 09:49 PM
SAS Super FREQ
Posts: 8,864

Re: Reading raw files

[ Edited ]

Hi:
As Reeza suggests, the ERROR message is accurately telling you what is wrong. You do not have a correct path to your CSV file.

I am not sure you followed ALL the code in the solution. I believe in the actual solution it has:
infile "&path/newemps.csv" dlm=',';

The &PATH is critical. It holds the name of the fully qualified path you are using. Remember in the very first Chapter of the book, the very first demo, you submitted a program to make the data. That program also makes the &PATH helper variable. Here are some examples:
%let path=/folders/myfolders; or
%let path=/folders/myfolders/ecprg013; <-- for SAS University Edition

%let path=c:\workshop\prg1; <-- Windows
%let path=/home/userid/prg1; <-- SAS On Demand

Next, your setup statements were supposed to include the LIBNAME for ORION:
libname orion "&path";

Because the &PATH helper variable is not just there for purposes of the LIBNAME statement, In Programming 1, we also intend for you to use &PATH in the INFILE statement to supply the fully qualified path.

Or, as an alternative, if you made the course files in C:\sas_class\pg1, then you could do this:
infile 'c:\sas_class\pg1\newemps.csv' dlm=',';

But that means every time you use an INFILE statement, you will have to remember and code the exact correct location.

cynthia


☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 212 views
  • 4 likes
  • 3 in conversation