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;
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;
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;
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 ....
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.