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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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;

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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