BookmarkSubscribeRSS Feed
Lysegroentblad
Obsidian | Level 7

Hi
I am new to SAS and have tried running examples of code trying to make them apply to my own dataset, but the log keeps coming up every colour but blue. I have a data set with both female and male rats who is tested on how fast they can complete a maze (time). I am also given the weight of the rats. Furthermore i am given their rank (alpha, beta, omega/AA, AB, AC etc) of the rat (experiment), time (latency). All in all I have 4 coloumns. I now want to see how these variables affect each other, i.e. how rank affect time, how time is affected by weight and if there is any correlation between gender and time and so on.
I have run this script so far: 

DATA MIT_EKS;
INFILE 'C:\Users\MajaThuren\OneDrive\Dokumenter\Skovbrugsvidenskab\StatBio\Exercises\Exercise 1\RATS.prn' FIRSTOBS=2;
INPUT experiment $ time $ weight $ gender $;
RUN;
PROC PRINT DATA=MIT_EKS; RUN;

My results viewer look like this:

Lysegroentblad_0-1644925965573.png

 

And then I'm quite stumped as to how i write a program that compares correlations between the variables?

I know it's simple, but I swear I tried for hours, I think I might just be a little thick.

 

A second question: I would also like to run a program that excludes one value from a variable. In the coloumn time I have an error value of -1,3. I know i can just remove it from my excel, but i would like to learn how to exclude one value with the help of code, that is when i'm running statistics for correlations between that variable (time) and fx weight.

 

Best regards

Maja

6 REPLIES 6
Quentin
Super User

Hi,

 

Please show the code you have tried (for the correlations). Are you perhaps using PROC CORR?  Please also show the log (with the errors) you are getting from that code.  

 

For excluding data, one way would be to use a WHERE statement.

 

Opinions about helping with homework vary; I think it's fine to ask for help with homework questions, but people will be better able to help you (and you will learn more) by showing what you have tried, and where you are stuck.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
Lysegroentblad
Obsidian | Level 7
These are the commands I've tried so far:

DATA MIT_EKS;
INFILE 'C:\Users\MajaThuren\OneDrive\Dokumenter\Skovbrugsvidenskab\StatBio\Exercises\Exercise 1\RATS.prn' FIRSTOBS=2;
INPUT Subject $ Rank $ Time $ Weight $ Gender $;
RUN;
PROC PRINT DATA=MIT_EKS; RUN;
PROC SORT; BY Time Weight; RUN;
 
PROC MEANS MEAN N VAR STD STDERR CV MIN MAX; RUN;

PROC CORR SPEARMAN PEARSON KENDALL;
VAR Time Weight; RUN;
PROC MEANS MEAN N VAR STD STDERR CV MIN MAX;
BY Time Weight; RUN;
PROC CORR SPEARMAN;
VAR Subject Experiment;
BY Time Weight; RUN;
PROC GLM;
CLASS Subject;
MODEL Time = Subject;
MEANS Subject / DUNNETT ('control'); RUN;

They stop working after: PROC SORT; BY Time Weight; RUN;
This is my log: NOTE: PROCEDURE GLM used (Total process time): real time 32.82 seconds cpu time 4.37 seconds 63 DATA MIT_EKS; 64 INFILE 'C:\Users\MajaThuren\OneDrive\Dokumenter\Skovbrugsvidenskab\StatBio\Exercises\Exercise 64 ! 1\RATS.prn' FIRSTOBS=2; 65 INPUT Subject $ Rank $ Time $ Weight $ Gender $; 66 RUN; NOTE: The infile 'C:\Users\MajaThuren\OneDrive\Dokumenter\Skovbrugsvidenskab\StatBio\Exercises\Exercise 1\RATS.prn' is: Filename=C:\Users\MajaThuren\OneDrive\Dokumenter\Skovbrugsvidenskab\StatBio\Exercises\Exercise 1\RATS.prn, RECFM=V,LRECL=32767,File Size (bytes)=10618, Last Modified=15. februar 2022 16:08:59, Create Time=14. februar 2022 10:02:35 NOTE: 192 records were read from the infile 'C:\Users\MajaThuren\OneDrive\Dokumenter\Skovbrugsvidenskab\StatBio\Exercises\Exercise 1\RATS.prn'. The minimum record length was 53. The maximum record length was 53. NOTE: The data set WORK.MIT_EKS has 192 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.12 seconds cpu time 0.12 seconds 67 PROC PRINT DATA=MIT_EKS; RUN; NOTE: Writing HTML Body file: sashtml3.htm NOTE: There were 192 observations read from the data set WORK.MIT_EKS. NOTE: PROCEDURE PRINT used (Total process time): real time 2.87 seconds cpu time 2.51 seconds 68 PROC SORT; BY Time Weight; RUN; NOTE: There were 192 observations read from the data set WORK.MIT_EKS. NOTE: The data set WORK.MIT_EKS has 192 observations and 5 variables. NOTE: PROCEDURE SORT used (Total process time): real time 0.05 seconds cpu time 0.06 seconds 69 70 PROC MEANS MEAN N VAR STD STDERR CV MIN MAX; RUN; ERROR: Statistics requested for printing, but no VAR statement has been specified. No printed output will be produced. ERROR: Neither the PRINT option nor a valid output statement has been given. NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE MEANS used (Total process time): real time 0.04 seconds cpu time 0.04 seconds 71 72 PROC CORR SPEARMAN PEARSON KENDALL; 73 VAR Time Weight; RUN; ERROR: Variable Time in list does not match type prescribed for this list. ERROR: Variable Weight in list does not match type prescribed for this list. NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE CORR used (Total process time): real time 0.02 seconds cpu time 0.03 seconds 74 PROC MEANS MEAN N VAR STD STDERR CV MIN MAX; 75 BY Time Weight; RUN; ERROR: Statistics requested for printing, but no VAR statement has been specified. No printed output will be produced. ERROR: Neither the PRINT option nor a valid output statement has been given. NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE MEANS used (Total process time): real time 0.03 seconds cpu time 0.03 seconds 76 PROC CORR SPEARMAN; 77 VAR Subject Experiment; ERROR: Variable Subject in list does not match type prescribed for this list. ERROR: Variable EXPERIMENT not found. 78 BY Time Weight; RUN; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE CORR used (Total process time): real time 0.02 seconds cpu time 0.03 seconds 79 PROC GLM; 80 CLASS Subject; 81 MODEL Time = Subject; ERROR: Variable Time in list does not match type prescribed for this list. NOTE: The previous statement has been deleted. 82 MEANS Subject / DUNNETT ('control'); RUN; ERROR: Effects used in the MEANS statement must have appeared previously in the MODEL statement. NOTE: The previous statement has been deleted.

This is an example of my data:

Lysegroentblad_0-1644939065000.png

 

 

andreas_lds
Jade | Level 19

I would start by importing numeric-content into numeric variables: delete $ after time and weight.

If that doesn't solve your problem (most likely it won't), please post the complete log.

Lysegroentblad
Obsidian | Level 7

Hi and thank you for responding.

When I delete the $ all values that are not decimal-numbers disapear from these columns - as such:

Lysegroentblad_0-1644939203602.png

 

ballardw
Super User

Looking at your first pictures the data is apparently using a comma for the decimal separator. This is a National Language Issue and if your SAS is running with a setting for country that using a dot as the decimal separator that would cause the issue (along with a log full of invalid data messages typically).

 

Try this to read the comma as decimal

DATA MIT_EKS;
INFILE 'C:\Users\MajaThuren\OneDrive\Dokumenter\Skovbrugsvidenskab\StatBio\Exercises\Exercise 1\RATS.prn' FIRSTOBS=2;
INPUT Subject $ Rank $ Time :Numx12. Weight :Numx12. Gender $;
RUN;
Lysegroentblad
Obsidian | Level 7

This worked! When I added numx12. to my numerical variables all the procs worked - Thank you.

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!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 896 views
  • 0 likes
  • 4 in conversation