Hi. I have the following code in SAS
data have;
input Make $ Model $ Type $ Origin $ DriveTrain $ MSRP Invoice;
datalines;
Acura MDX SUV Asia All 36945 33337
BMW X3 SUV Europe All 37000 33873
BMW 325i Sedan Europe All 52195 47720
Dodge Durango SUV USA All 32235 29472
Dodge Neon Sedan USA Front 13670 12849
;
pct_change = (MSRP - Invoice)/Invoice;
format pct_change percent10.;
where Type = "SUV" and DriveTrain = "All";
run;
proc print data = have;
title 'All wheel drive SUVs with less than 10% change in Price';
var Make Model MSRP Invoice pct_change;
where pct_change le 0.1;
run;
and I'm receiving the following errors
80 pct_change = (MSRP - Invoice)/Invoice; __________ 180 ERROR 180-322: Statement is not valid or it is used out of proper order.
I don't know what I have done wrong and this should be a simple code so it really confused me. Any help? Thank you in advance!
Compare below syntactically working code to your version and you should understand where you've got it wrong.
data have;
input Make $ Model $ Type $ Origin $ DriveTrain $ MSRP Invoice;
pct_change = (MSRP - Invoice)/Invoice;
format pct_change percent10.;
if Type = "SUV" and DriveTrain = "All";
datalines;
Acura MDX SUV Asia All 36945 33337
BMW X3 SUV Europe All 37000 33873
BMW 325i Sedan Europe All 52195 47720
Dodge Durango SUV USA All 32235 29472
Dodge Neon Sedan USA Front 13670 12849
;
proc print data = have;
title 'All wheel drive SUVs with less than 10% change in Price';
var Make Model MSRP Invoice pct_change;
where pct_change le 0.1;
run;
Compare below syntactically working code to your version and you should understand where you've got it wrong.
data have;
input Make $ Model $ Type $ Origin $ DriveTrain $ MSRP Invoice;
pct_change = (MSRP - Invoice)/Invoice;
format pct_change percent10.;
if Type = "SUV" and DriveTrain = "All";
datalines;
Acura MDX SUV Asia All 36945 33337
BMW X3 SUV Europe All 37000 33873
BMW 325i Sedan Europe All 52195 47720
Dodge Durango SUV USA All 32235 29472
Dodge Neon Sedan USA Front 13670 12849
;
proc print data = have;
title 'All wheel drive SUVs with less than 10% change in Price';
var Make Model MSRP Invoice pct_change;
where pct_change le 0.1;
run;
You need to understand what DATALINES does, so you have to Read the Documentation (Maxim 1):
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.