Hi!
I am a MSc student and I am having difficulty running my SAS code. I am looking at mammary gland data from pigs. Each variable was measured once. The project has a completely randomized design.
I am trying to run ANOVAs and tukeys tests on the data. My descriptive stats will run, but thats as far as it will go.
Here is my code so far:
Data GLANDES_TRUIE;
infile "/home/u62306126/sasuser.v94/LYS3/glande_stats.csv" dlm="," firstobs=2;
input TRUIE TRAIT ADN_PAR_SEC ARN_PAR_SEC BW NBR_TET
PCT_GRAS_SEC PCT_MS PCT_PROT_SEC PDS_EXTRA PDS_PAR PDS_PAR_TET
RATIO_ARN_ADN RATIO_EXTRA_PAR RATIO_PROT_ADN RATIO_PROT_ARN
TOT_ADN_PAR TOT_ADN_TET TOT_ARN_PAR TOT_ARN_TET TOT_GRAS_PAR TOT_PROT_PAR;
Run;
PROC CONTENTS; run;
data GLANDES_TRUIE;
set lecture_GLANDES;
if TRAIT=1 then TRT="CONTROL";
if TRAIT=2 then TRT="SOYBEAN";
if TRAIT=3 then TRT="CASEIN";
if TRAIT=4 then TRT="LYSINE";
trt_TRUIE=compress(SUBSTR(TRT,1,3)||"_"||truie);
proc print;
run;
/* descriptive stats */
proc means data=GLANDES_TRUIE maxdec=2;
class TRAIT;
var ADN_PAR_SEC ARN_PAR_SEC BW NBR_TET
PCT_GRAS_SEC PCT_MS PCT_PROT_SEC PDS_EXTRA PDS_PAR PDS_PAR_TET
RATIO_ARN_ADN RATIO_EXTRA_PAR RATIO_PROT_ADN RATIO_PROT_ARN
TOT_ADN_PAR TOT_ADN_TET TOT_ARN_PAR TOT_ARN_TET TOT_GRAS_PAR TOT_PROT_PAR;
run;
/* descriptive stats separate tables for each variable */
proc sort data=GLANDES_TRUIE;
by variable trait trt truie;
run;
proc means data=GLANDES_TRUIE maxdec=2;
class trt;
var GLANDE;
BY variable;
run;
/* each variable analyzed separately */
proc sort data=GLANDES_TRUIE;
BY variable;
proc mixed data=GLANDES_TRUIE;
class TRAIT truie;
model GLANDE=TRAIT/ outp=outpred;
repeated / group=TRAIT;
ods output tests3=tests;
lsmeans TRAIT / cl;
ods output lsmeans=lsm;
BY variable;
run;
/* non-parametric analysis */
proc npar1way DATA=GLANDES_TRUIE wilcoxon;
class TRT;
var GLANDE;
by variable;
ods output WilcoxonTest=WilcoxonTest (rename=nValue1=Wilcoxon);
run;
proc print data=WilcoxonTest noobs;
where name1="PT2_WIL";
var variable;
var Wilcoxon / style(Column)=[background=colorFMT.];
format Wilcoxon 6.4;
run;
Thank you!!
Caroline
Hi, when you say "that's as far as it will go", what happens after that? If you look at the log, do you see ERROR messages? One of the most important parts of learning SAS learning how to read the log. You always want to review your log before you look at any results. If you the log has ERRORs or WARNINGs, you need to fix them, before you trust your results.
If you look at your log and can't figure out what it means, please paste the log into a post here, and people can help you. One thing I noticed if you have a lot of code like:
proc sort data=GLANDES_TRUIE;
by variable trait trt truie; * <-- you do not have a variable named VARIABLE ;
run;
The second line is a BY statement, commonly used in SAS for processing data in groups, or in this case for sorting data into groups. A BY statement expects the list of words after the word BY to be the names of variables that exist in the input data. With this code, it will expect the data to have a variable named VARIABLE. I don't think that exists in your data, which should trigger an error message. Perhaps try:
proc sort data=GLANDES_TRUIE;
by trait trt truie; * <-- removed the word VARIABLE ;
run;
proc means data=GLANDES_TRUIE maxdec=2;
class trt;
var GLANDE;
BY trait trt truie; * <-- replaced the word VARIABLE with the list of variables you sorted by above;
run;
Note also above that the CLASS statement and BY statement have similar purposes in PROC MEANS. While they could be used together, it's unlikely this will give you the result you want. It would probably be better for you too think about the groups you want to have PROC MEANS output for, and then use either a CLASS statement or BY statement to define those groups.
Please be specific and tell us what EXACT part of your code doesn't work. Also please tell us what about this doesn't work — are there errors in the log? do you get output but its the wrong output?
If you get errors in the log, please show us the ENTIRE log for this PROC, copy the log as text and paste it into the window that appears when you click on the </> icon.
If the code produces output but its the wrong output, show us the output and explain what you think is wrong.
@PaigeMiller @Quentin -- thank you for taking the time to look at this
Here is my output from the log when I try to run my data:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; NOTE: ODS statements in the SAS Studio environment may disable some output features. 69 70 Data GLANDES_TRUIE; 71 infile "/home/u62306126/sasuser.v94/LYS3/glande_stats.csv" dlm="," firstobs=2; 72 input TRUIE TRAIT ADN_PAR_SEC ARN_PAR_SEC BW NBR_TET 73 PCT_GRAS_SEC PCT_MS PCT_PROT_SEC PDS_EXTRA PDS_PAR PDS_PAR_TET 74 RATIO_ARN_ADN RATIO_EXTRA_PAR RATIO_PROT_ADN RATIO_PROT_ARN 75 TOT_ADN_PAR TOT_ADN_TET TOT_ARN_PAR TOT_ARN_TET TOT_GRAS_PAR TOT_PROT_PAR; 76 Run; NOTE: The infile "/home/u62306126/sasuser.v94/LYS3/glande_stats.csv" is: Filename=/home/u62306126/sasuser.v94/LYS3/glande_stats.csv, Owner Name=u62306126,Group Name=oda, Access Permission=-rw-r--r--, Last Modified=09Feb2024:13:41:07, File Size (bytes)=8809 NOTE: 64 records were read from the infile "/home/u62306126/sasuser.v94/LYS3/glande_stats.csv". The minimum record length was 52. The maximum record length was 136. NOTE: SAS went to a new line when INPUT statement reached past the end of a line. NOTE: The data set WORK.GLANDES_TRUIE has 63 observations and 22 variables. 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 764.62k OS Memory 21668.00k Timestamp 02/11/2024 05:00:50 PM Step Count 41 Switch Count 2 Page Faults 0 Page Reclaims 122 Page Swaps 0 Voluntary Context Switches 15 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 264 77 78 PROC CONTENTS; run; NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.02 seconds user cpu time 0.03 seconds system cpu time 0.00 seconds memory 1743.93k OS Memory 21928.00k Timestamp 02/11/2024 05:00:50 PM Step Count 42 Switch Count 0 Page Faults 0 Page Reclaims 125 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 16 79 data GLANDES_TRUIE; 80 set lecture_GLANDES; ERROR: File WORK.LECTURE_GLANDES.DATA does not exist. 81 if TRAIT=1 then TRT="CONTROL"; 82 if TRAIT=2 then TRT="SOYBEAN"; 83 if TRAIT=3 then TRT="CASEIN"; 84 if TRAIT=4 then TRT="LYSINE"; 85 trt_TRUIE=compress(SUBSTR(TRT,1,3)||"_"||truie); NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 85:44 NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.GLANDES_TRUIE may be incomplete. When this step was stopped there were 0 observations and 4 variables. WARNING: Data set WORK.GLANDES_TRUIE 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 633.96k OS Memory 21668.00k Timestamp 02/11/2024 05:00:50 PM Step Count 43 Switch Count 0 Page Faults 0 Page Reclaims 58 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 16 86 proc print; 87 run; NOTE: There were 63 observations read from the data set WORK.GLANDES_TRUIE. NOTE: PROCEDURE PRINT used (Total process time): real time 0.11 seconds user cpu time 0.12 seconds system cpu time 0.00 seconds memory 815.25k OS Memory 21924.00k Timestamp 02/11/2024 05:00:50 PM Step Count 44 Switch Count 0 Page Faults 0 Page Reclaims 96 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 96 88 89 /* simpler code from stats lectures */ 90 Proc glimmix data=GLANDES_TRUIE; 91 class TRAIT TRUIE; 92 model ADN_PAR_SEC ARN_PAR_SEC BW NBR_TET ___________ 73 NOTE: PROCEDURE GLIMMIX used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 649.84k OS Memory 21924.00k Timestamp 02/11/2024 05:00:50 PM Step Count 45 Switch Count 0 Page Faults 0 Page Reclaims 134 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 NOTE: The SAS System stopped processing this step because of errors. ERROR 73-322: Expecting an =. 93 PCT_GRAS_SEC PCT_MS PCT_PROT_SEC PDS_EXTRA PDS_PAR PDS_PAR_TET 94 RATIO_ARN_ADN RATIO_EXTRA_PAR RATIO_PROT_ADN RATIO_PROT_ARN 95 TOT_ADN_PAR TOT_ADN_TET TOT_ARN_PAR TOT_ARN_TET TOT_GRAS_PAR TOT_PROT_PAR=TRAIT; _ 22 200 ERROR 22-322: Syntax error, expecting one of the following: a name, ;, (, *, -, /, :, @, _CHARACTER_, _CHAR_, _NUMERIC_, |. ERROR 200-322: The symbol is not recognized and will be ignored. 96 covtest "block=0" 0.; 97 lsmeans TRUIE/pdiff adjust=tukey lines; 98 Run; 99 100 /* descriptive stats */ 101 proc means data=GLANDES_TRUIE maxdec=2; 102 class TRAIT; 103 var ADN_PAR_SEC ARN_PAR_SEC BW NBR_TET 104 PCT_GRAS_SEC PCT_MS PCT_PROT_SEC PDS_EXTRA PDS_PAR PDS_PAR_TET 105 RATIO_ARN_ADN RATIO_EXTRA_PAR RATIO_PROT_ADN RATIO_PROT_ARN 106 TOT_ADN_PAR TOT_ADN_TET TOT_ARN_PAR TOT_ARN_TET TOT_GRAS_PAR TOT_PROT_PAR; 107 run; NOTE: There were 63 observations read from the data set WORK.GLANDES_TRUIE. NOTE: PROCEDURE MEANS used (Total process time): real time 0.09 seconds user cpu time 0.09 seconds system cpu time 0.00 seconds memory 6715.43k OS Memory 27568.00k Timestamp 02/11/2024 05:00:51 PM Step Count 46 Switch Count 1 Page Faults 0 Page Reclaims 1579 Page Swaps 0 Voluntary Context Switches 34 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 32 108 109 /* descriptive stats separate tables for each variable */ 110 proc sort data=GLANDEs_truie; 111 by trait truie; 112 run; NOTE: There were 63 observations read from the data set WORK.GLANDES_TRUIE. NOTE: The data set WORK.GLANDES_TRUIE has 63 observations and 22 variables. NOTE: PROCEDURE SORT used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 933.78k OS Memory 22696.00k Timestamp 02/11/2024 05:00:51 PM Step Count 47 Switch Count 2 Page Faults 0 Page Reclaims 113 Page Swaps 0 Voluntary Context Switches 12 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 264 113 114 proc means data=GLANDES_TRUIE maxdec=2; 115 class TRAIT; 116 var GLANDE; ERROR: Variable GLANDE not found. 117 BY TRAIT TRUIE; 118 run; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE MEANS used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 500.34k OS Memory 22436.00k Timestamp 02/11/2024 05:00:51 PM Step Count 48 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 119 120 /* each variable analyzed separately */ 121 proc sort data=GLANDES_TRUIE; 122 BY variable; ERROR: Variable VARIABLE not found. NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SORT used (Total process time): real time 0.00 seconds user cpu time 0.01 seconds system cpu time 0.00 seconds memory 437.50k OS Memory 22436.00k Timestamp 02/11/2024 05:00:51 PM Step Count 49 Switch Count 0 Page Faults 0 Page Reclaims 49 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 123 proc mixed data=GLANDES_TRUIE; 124 class TRAIT truie; 125 model GLANDE=TRAIT/ outp=outpred; ERROR: Variable GLANDE not found. NOTE: PROCEDURE MIXED used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 487.12k OS Memory 22436.00k Timestamp 02/11/2024 05:00:51 PM Step Count 50 Switch Count 0 Page Faults 0 Page Reclaims 49 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 8 NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.OUTPRED may be incomplete. When this step was stopped there were 0 observations and 0 variables. WARNING: Data set WORK.OUTPRED was not replaced because this step was stopped. 126 repeated / group=TRAIT; 127 ods output tests3=tests; 128 lsmeans TRAIT / cl; 129 ods output lsmeans=lsm; 130 BY variable; 131 run; 132 133 /* non-parametric analysis */ 134 proc npar1way DATA=GLANDES_TRUIE wilcoxon; 135 class TRAIT; 136 var GLANDE; ERROR: Variable GLANDE not found. 137 by TRAIT TRUIE; 138 ods output WilcoxonTest=WilcoxonTest (rename=nValue1=Wilcoxon); 139 run; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE NPAR1WAY used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 442.40k OS Memory 22436.00k Timestamp 02/11/2024 05:00:51 PM Step Count 51 Switch Count 1 Page Faults 0 Page Reclaims 48 Page Swaps 0 Voluntary Context Switches 7 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 WARNING: Output 'WilcoxonTest' was not created. Make sure that the output object name, label, or path is spelled correctly. Also, verify that the appropriate procedure options are used to produce the requested output object. For example, verify that the NOPRINT option is not used. WARNING: Output 'lsmeans' was not created. Make sure that the output object name, label, or path is spelled correctly. Also, verify that the appropriate procedure options are used to produce the requested output object. For example, verify that the NOPRINT option is not used. WARNING: Output 'tests3' was not created. Make sure that the output object name, label, or path is spelled correctly. Also, verify that the appropriate procedure options are used to produce the requested output object. For example, verify that the NOPRINT option is not used. 140 141 proc print data=WilcoxonTest noobs; ERROR: File WORK.WILCOXONTEST.DATA does not exist. 142 where name1="PT2_WIL"; WARNING: No data sets qualify for WHERE processing. 143 var TRAIT TRUIE; 144 var Wilcoxon / style(Column)=[background=colorFMT.]; __________ 22 202 ERROR 22-322: Syntax error, expecting one of the following: ;, STYLE. ERROR 202-322: The option or parameter is not recognized and will be ignored. 145 format Wilcoxon 6.4; 146 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 228.84k OS Memory 22176.00k Timestamp 02/11/2024 05:00:51 PM Step Count 52 Switch Count 0 Page Faults 0 Page Reclaims 16 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 8 147 148 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 158
79 data GLANDES_TRUIE;
80 set lecture_GLANDES;
ERROR: File WORK.LECTURE_GLANDES.DATA does not exist.
The data set lecture_glandes does not exist. You have to fix this in order for the rest of your code to work properly.
Another lesson in SAS is that you rarely (never) want to write an entire program and run it all. Because a problem in step #2 will make everything after it useless. It's much easier to write the first DATA step, run it, and debug it. Then write the next step, run it, and debug it. After you have all the steps working, it's a good idea to start a new SAS session and run them all at once. But while you're writing code, running each step one-at-a-time as you are writing is usually more helpful than running the whole program.
Thank you! I've fixed that. The error message:
ERROR 73-322: Expecting an =. 73 PCT_GRAS_SEC PCT_MS PCT_PROT_SEC PDS_EXTRA PDS_PAR PDS_PAR_TET 74 RATIO_ARN_ADN RATIO_EXTRA_PAR RATIO_PROT_ADN RATIO_PROT_ARN 75 TOT_ADN_PAR TOT_ADN_TET TOT_ARN_PAR TOT_ARN_TET TOT_GRAS_PAR TOT_PROT_PAR=TRAIT/outp=outpred;
Is relating to this section of code:
ERROR 73-322: Expecting an =.
73 PCT_GRAS_SEC PCT_MS PCT_PROT_SEC PDS_EXTRA PDS_PAR PDS_PAR_TET
74 RATIO_ARN_ADN RATIO_EXTRA_PAR RATIO_PROT_ADN RATIO_PROT_ARN
75 TOT_ADN_PAR TOT_ADN_TET TOT_ARN_PAR TOT_ARN_TET TOT_GRAS_PAR TOT_PROT_PAR=TRAIT/outp=outpred;
I am confused as to why it says it is expecting a "=". There is an equal sign between the variables and trait
According to GLIMMIX documentation: https://documentation.sas.com/doc/en/statcdc/14.2/statug/statug_glimmix_syntax15.htm
the syntax is:
MODEL response <(response-options)> = <fixed-effects> </ model-options>;
e.g.,
model y=x / ALPHA=0.07;
And, if I see it correctly in your log, you don't have it in this form.
Bart
@caroline_rg wrote:
Hi Bart,
Are you able to explain how it is not in this form? All of my variables (the "y") are equal to the trait (the "x"). I have changed the code to have "/alpha=0.05", but get the same error message. I'm not sure why SAS isn't recognizing my "=" between the y and x
Because you don't have one.
92 model ADN_PAR_SEC ARN_PAR_SEC BW NBR_TET
93 PCT_GRAS_SEC PCT_MS PCT_PROT_SEC PDS_EXTRA PDS_PAR PDS_PAR_TET
94 RATIO_ARN_ADN RATIO_EXTRA_PAR RATIO_PROT_ADN RATIO_PROT_ARN
95 TOT_ADN_PAR TOT_ADN_TET TOT_ARN_PAR TOT_ARN_TET TOT_GRAS_PAR TOT_PROT_PAR=TRAIT;
Which of those variables is the DEPENDENT variable (the one that the model is going to predict the value for)? Place that before the = and then list the INEDEPENDENT variables (the ones used as the basis for the predictions) after the =.
@caroline_rg wrote:
Hi Bart,
Are you able to explain how it is not in this form? All of my variables (the "y") are equal to the trait (the "x"). I have changed the code to have "/alpha=0.05", but get the same error message. I'm not sure why SAS isn't recognizing my "=" between the y and x
In PROC GLIMMIX (as shown by @yabwon by quoting the SAS documentation), you can have only a single Y variable. You cannot have multiple Y variables. So, assuming the Y variable is ADN_PAR_SEC the command you want is
model ADN_PAR_SEC = BW NBR_TET ... ;
and then you include BW and NBR_TET and all the rest of the X-variables (also called independent variables) in the model statement.
NOTE: Your code actually began with
model ADN_PAR_SEC ARN_PAR_SEC BW NBR_TET
and the first two variables are identical, and you cannot enter a variable into the model statement more than once.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.