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 ....
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.
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.