I am trying to create a new variable "bmi" and print only variables childid, ht5, bweight, and bmi. When I run this I keep getting these errors. What am I missing?
data question2; infile "/home/u59352003/btt.dat.txt"; input childid 1-4 sex 6 bweight 8-11 gestage 13-14 momage 16-17 parity 19 mdbp 21-23 msbp 25-27 momeduc 29 mmedaid 31; socio 33 dbp5 35-37 sbp5 39-41 ht5 43 -47 wt5 49-52 hdl5 54 -57 trig5 64-67 smoke5 69 medaid5 71 socio5 73; bmi = bweight/(ht5^2); run; proc print data = question2 (obs=10); var childid ht5 bweight bmi run;
Semicolons end a statement:
The code you show (slightly rearranged for readability) and a semicolon in the middle of an input statement. That ended the input so the following bits of :socio 33 dbp5 35-37 (etc) are not complete syntactically correct statements.
Remove the highlighted semicolon.
data question2; infile "/home/u59352003/btt.dat.txt"; input childid 1-4 sex 6 bweight 8-11 gestage 13-14 momage 16-17 parity 19 mdbp 21-23
msbp 25-27 momeduc 29 mmedaid 31; socio 33 dbp5 35-37 sbp5 39-41 ht5 43 -47
wt5 49-52 hdl5 54 -57 trig5 64-67 smoke5 69 medaid5 71 socio5 73; bmi = bweight/(ht5^2); run; proc print data = question2 (obs=10); var childid ht5 bweight bmi run
In the future any questions about errors or messages in the log you do not understand you should copy the entire data step or procedure code from the log along with the notes, messages, warnings and/or errors. Paste all the text into a text box opened on the forum with the </> icon.
The errors you referenced would have had diagnostic characters appearing under the place that SAS found the syntax problem but by only copying part of the error you didn't show those characters. Paste in a code box to prevent the message windows from reformatting the text and the diagnostic characters make more sense.
thank you for your reply! even after removing the semicolon you highlighted, I am still getting some errors. Hopefully this will be more helpful?
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 68 69 data question2; 70 infile "/home/u59352003/btt.dat.txt"; 71 input childid 1-4 sex 6 bweight 8-11 gestage 13-14 momage 16-17 parity 19 mdbp 21-23 msbp 25-27 momeduc 29 mmedaid 31 71 ! socio 33 dbp5 35-37 sbp5 39-41 ht5 43 -47 wt5 49-52 hdl5 54 -57 trig5 64-67 smoke5 69 medaid5 71 socio5 73; 72 bmi = bweight/(ht5^2); _ 22 76 ERROR 22-322: Syntax error, expecting one of the following: <, <=, =, >, >=, EQ, GE, GT, LE, LT, NE, NG, NL, ^=, ~=. ERROR 76-322: Syntax error, statement will be ignored. 73 run; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.QUESTION2 may be incomplete. When this step was stopped there were 0 observations and 21 variables. WARNING: Data set WORK.QUESTION2 was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 646.12k OS Memory 24228.00k Timestamp 09/15/2021 04:29:08 AM Step Count 52 Switch Count 0 Page Faults 0 Page Reclaims 70 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 8 74 proc print data = question2 (obs=10); 75 var childid ht5 bweight bmi; ERROR: Variable HT5 not found. 76 run; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE PRINT used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 485.71k OS Memory 24228.00k Timestamp 09/15/2021 04:29:08 AM Step Count 53 Switch Count 0 Page Faults 0 Page Reclaims 50 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 77 78 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 88
Not sure what you are trying to do with this statement:
bmi = bweight/(ht5^2);
If you are trying to square HT5 then use two asterisks (ht5**2).
The up arrow is not a valid arithmetic operator, see the documentation.
I recommend that you bookmark the "SAS Programmer's Guide: Essentials" and use it to acquaint yourself with the basics of the SAS language whenever needed.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.