DATA Step, Macro, Functions and more

trying to create variable with imported data

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

trying to create variable with imported data

I am trying to create a variable for price per carat. I keep recieving an error message saying the command is wrong or not in the proper place. 

the code I am trying to use is as follows

 

ILENAME CSV "/folders/myfolders/homeworkdata/diamond.csv" TERMSTR=CRLF;


/** Import the CSV file. **/

PROC IMPORT DATAFILE=CSV
OUT=problem4a
DBMS=CSV
REPLACE;
guessingrows = 1000;
RUN;

pricepercarat = (price/carat);
/** Print the results. **/

PROC PRINT DATA=problem4a; RUN;

/** Unassign the file reference. **/

FILENAME CSV;

proc print data=problem4a (firstobs=131 obs=179);
run;

 

 


Accepted Solutions
Solution
‎01-28-2016 08:05 PM
Super User
Posts: 3,110

Re: trying to create variable with imported data

FILENAME CSV "/folders/myfolders/homeworkdata/diamond.csv" TERMSTR=CRLF;

/** Import the CSV file. **/
PROC IMPORT DATAFILE=CSV
OUT=problem4a
DBMS=CSV
REPLACE;
guessingrows = 1000;
RUN;

data problem4a;
  set problem4a;
  pricepercarat = (price/carat);
run;

/** Print the results. **/
PROC PRINT DATA=problem4a; RUN;
/** Unassign the file reference. **/
FILENAME CSV;
proc print data=problem4a (firstobs=131 obs=179);
run;

View solution in original post


All Replies
Solution
‎01-28-2016 08:05 PM
Super User
Posts: 3,110

Re: trying to create variable with imported data

FILENAME CSV "/folders/myfolders/homeworkdata/diamond.csv" TERMSTR=CRLF;

/** Import the CSV file. **/
PROC IMPORT DATAFILE=CSV
OUT=problem4a
DBMS=CSV
REPLACE;
guessingrows = 1000;
RUN;

data problem4a;
  set problem4a;
  pricepercarat = (price/carat);
run;

/** Print the results. **/
PROC PRINT DATA=problem4a; RUN;
/** Unassign the file reference. **/
FILENAME CSV;
proc print data=problem4a (firstobs=131 obs=179);
run;
Super Contributor
Posts: 490

Re: trying to create variable with imported data

You are getting the error 

 

 ERROR 180-322: Statement is not valid or it is used out of proper order.

because you create a variable out of the data step _after the run statment_.... and you can not do that.

 

 

PROC IMPORT DATAFILE=CSV
OUT=problem4a
DBMS=CSV
REPLACE;
guessingrows = 1000;
RUN;
pricepercarat = (price/carat);

PROC IMPORT reads data from an external data source and writes it to a SAS data set. Overview: IMPORT Procedure

 

In sas Coding you have data step and Procedures and inside these you add your code, which end by RUN or QUIT statment. When you run your statment 

RUN;
pricepercarat = (price/carat);

in no where like you did. Where do you think it will run? And for which data. Be carefull ....

 

 

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 161 views
  • 0 likes
  • 3 in conversation