Hi, I am trying to complete a HW assignment and I keep getting a blank table for the question 6. What am I doing wrong to make the table not show? Find attached a few screenshots of the situation.
What does your log show?
It is best to paste code and/or log information into a text box opened on the forum with the </>. Copy text and paste. That way if we see something that needs correction it is much easier to edit than to retype from scratch. (I'm not the only one lazy that way.)
Since you have 4 procedure calls that could create a table, Proc Contents, Proc Print and two calls to Proc Means you really need to state explicitly which you are having problems with.
/* S325 HW 1 By Joshua Gataric 9/1/2022 */ data bmi; infile '/home/u62108616/S325/hw1.dat'; input Id age Height Weight Gender; run; /* 54 observations in the log file */ proc contents data = bmi; run; proc print data = bmi; title1 'BMI Data for senior people'; title2 'by Alva Hospital'; run; title 'By Alva Hospital'; run; proc means data = bmi maxdec = 4; var Weight Height; run; proc means data = bmi; class Gender; var age Weight Height; run;
The reason that last proc means generated no results is in the log
96 proc means data = bmi; 97 class Gender; 98 var age Weight Height; 99 run; WARNING: A class or frequency variable is missing on every observation. NOTE: There were 54 observations read from the data set WORK.BMI. NOTE: PROCEDURE MEANS used (Total process time):
If you look above when you read the data you have attempted to read Gender as a numeric value and SAS told you that was a problem:
NOTE: Invalid data for Gender in line 1 33-36. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 1 10001 61 236.00 74.50 Male 36 Id=10001 age=61 Height=236 Weight=74.5 Gender=. _ERROR_=1 _N_=1 NOTE: Invalid data for Gender in line 2 33-38. 2 10002 55 141.00 69.00 Female 38 Id=10002 age=55 Height=141 Weight=69 Gender=. _ERROR_=1 _N_=2 NOTE: Invalid data for Gender in line 3 33-38.
The Rule line allows you to count spaces when pasted as text directly from the log into a text box. Since you did not do that the message window removed some of the spaces so that the 10001 does not appear under the first -.
You Gender values are Character, Male and Female.
Your input statement does not indicate that Gender should be read as character. Use
input Id age Height Weight Gender $;
in the first data step and that should fix the problem. The $ tells SAS that Gender should be read as character and will default to 8 characters in length, which should be long enough to hold values of Female and Male. If you have other values longer than 8 characters you need to specify an informat that would read longer values. Example that would read up to 15 characters. The : helps align data of different lengths in this case.
input Id age Height Weight Gender : $15. ;
You may want to also check the order of the variables you are reading in the .dat file, not sure of the what units they are measured in but the values for height look a little suspicious.
for example is the Height value for the first record really 236?
1 10001 61 236.00 74.50 Male 36
Id=10001 age=61 Height=236 Weight=74.5 Gender=. _ERROR_=1 _N_=1
Also there seems to be a variable at the end of each record (ex. the value of 36 for the first record) - again not sure what this is & maybe it is not important & was intentionally not read in.
Not treating Gender as a character was indeed it. Now for question 7, is this what I am supposed to do?
proc print data = bmi(obs=20); proc means data = bmi maxdec = 3; class Gender; var age Weight Height; run;
I don't know your instructor. It may be that the Proc means should use the same observations as the Proc Print did.
Sometimes half of a problem is determining what your instructor means.
@JoshuaG wrote:
Not treating Gender as a character was indeed it. Now for question 7, is this what I am supposed to do?
proc print data = bmi(obs=20); proc means data = bmi maxdec = 3; class Gender; var age Weight Height; run;
@tom_grant wrote:
You may want to also check the order of the variables you are reading in the .dat file, not sure of the what units they are measured in but the values for height look a little suspicious.
for example is the Height value for the first record really 236?
1 10001 61 236.00 74.50 Male 36Id=10001 age=61 Height=236 Weight=74.5 Gender=. _ERROR_=1 _N_=1Also there seems to be a variable at the end of each record (ex. the value of 36 for the first record) - again not sure what this is & maybe it is not important & was intentionally not read in.
The number at the end of each line is the length of that line. Since the error message said the value read for GENDER in columns 33 to 36 was not a valid number then the e in Male is the last character on that line.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Ready to level-up your skills? Choose your own adventure.