BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MadQuidd
Obsidian | Level 7

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star
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

2 REPLIES 2
SASKiwi
PROC Star
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;
mohamed_zaki
Barite | Level 11

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

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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