BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
MisterJenn
Fluorite | Level 6

I keep getting an error message every time I run the code. I went over it with my TA and assumed everything was correct but I keep getting error message. 

This is the error message I get; ERROR 180-322: Statement is not valid or it is used out of proper order.

Please help the assignment is due today!

* I am trying to answer question 1

 

 



libname hw3 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Week 3'; data fit1temp; set hw3.fit2; if upcase(compress(smoke)) = "CURRENTSMOKER" then currentsmoker = 1; else if upcase(compress(smoke)) = "NONSMOKER" or upcase(compress(smoke)) = "FORMERSMOKER" then currentsmoker = 0; if blvfx = "yes" or blnspfx = "yes" then any_base_frac = 1; else if blvfx = "no" and blnspfx = "no" then = any_base_frac = 0; if newvfx = "yes" and newnspfx = "yes" then any_new_frac = 1; else if newvfx = "no" and newnspfx = "no" then any_new_frac = 0; if bmi > 25 then bmi2 = "overweight"; else if 0 < bmi <= 25 then bmi2 = "normal"; if 0 < bmi <= 18 then bmi3 = "underweight"; else if 18 < bmi <= 25 then bmi3 = "normal"; else if bmi > 25 then bmi3 = "overweight"; bmi1_ind = (bmi > 25); bmi2_ind = (18 < bmi <= 25); bmi3_ind = (0 < bmi <= 18); i_tx = (tx = "Alendronate"); diff_bmd = cobmd-blbmd; age = (dov - dob)/365.25; run;
libname hw3 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Week 3';
NOTE: Libref HW3 was successfully assigned as follows:
      Engine:        V9
      Physical Name: \\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Week 3
50   data fit1temp;
51   set hw3.fit2;
52   if upcase(compress(smoke)) = "CURRENTSMOKER" then currentsmoker = 1;
53   else if upcase(compress(smoke)) = "NONSMOKER" or
54   upcase(compress(smoke)) = "FORMERSMOKER" then currentsmoker = 0;
55   if blvfx = "yes" or blnspfx = "yes" then any_base_frac = 1;
56   else if blvfx = "no" and blnspfx = "no" then = any_base_frac = 0;
                                                  -
                                                  180
ERROR 180-322: Statement is not valid or it is used out of proper order.

57   if newvfx = "yes" and newnspfx = "yes" then any_new_frac = 1;
58   else if newvfx = "no" and newnspfx = "no" then any_new_frac = 0;
59   if bmi > 25 then bmi2 = "overweight";
60   else if 0 < bmi <= 25 then bmi2 = "normal";
61   if 0 < bmi <= 18 then bmi3 = "underweight";
62   else if 18 < bmi <= 25 then bmi3 = "normal";
63   else if bmi > 25 then bmi3 = "overweight";
64
65   bmi1_ind = (bmi > 25);
66   bmi2_ind = (18 < bmi <= 25);
67   bmi3_ind = (0 < bmi <= 18);
68   i_tx = (tx = "Alendronate");
69   diff_bmd = cobmd-blbmd;
70   age = (dov - dob)/365.25;
71   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FIT1TEMP may be incomplete.  When this step was stopped there were 0
         observations and 22 variables.
WARNING: Data set WORK.FIT1TEMP was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
55   if blvfx = "yes" or blnspfx = "yes" then any_base_frac = 1;
56   else if blvfx = "no" and blnspfx = "no" then = any_base_frac = 0;
                                                  -
                                                  180
ERROR 180-322: Statement is not valid or it is used out of proper order.

You can't follow THEN with an = sign.

 

Perhaps this is what you meant:

 

else if blvfx = "no" and blnspfx = "no" then any_base_frac = 0;

 

--
Paige Miller

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

You can't insert a PROC FREQ in the middle of a DATA step. The PROC statement would immediately end the data step, if the preceding IF had been properly terminated with a semicolon.

The data step code following the PROC FREQ without a new DATA statement would then also be invalid.

Kurt_Bremser
Super User

And do not post pictures of code and logs.

Post logs by copy/pasting the text into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

Post code in a similar way, but use the "little running man" right next to the indicated button.

Patrick
Opal | Level 21

You need to post the SAS log that shows the very first error (and ideally the very first warning) in the SAS log. 

The error you post (proc freq in the middle of a data step) is not reflected in the code you post.

 

As a side story: You can use the yrdif() function to calculate the age. This function will also take leap years into account. age=yrdif(dob,dov,'age');

PaigeMiller
Diamond | Level 26
55   if blvfx = "yes" or blnspfx = "yes" then any_base_frac = 1;
56   else if blvfx = "no" and blnspfx = "no" then = any_base_frac = 0;
                                                  -
                                                  180
ERROR 180-322: Statement is not valid or it is used out of proper order.

You can't follow THEN with an = sign.

 

Perhaps this is what you meant:

 

else if blvfx = "no" and blnspfx = "no" then any_base_frac = 0;

 

--
Paige Miller
MisterJenn
Fluorite | Level 6
thank you sooo much!!! I can't believe it was that simple!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 940 views
  • 4 likes
  • 4 in conversation