Hello,
I need to run chi-sq tests for a final project for school and I was not taught how to manipulate the data to make it a format to run the test when pulling data from a library/csv file. I am trying to do DistrictGroup vs. Monthly Rainfall with the amount of rainfall as the count.
I need the data to look like this:
Month
District Group Jul96 Aug96 Sep96 ...
Cairns/Mulgrave(Dry) 0 6 0
NorthCairns 45.8 9.6 7.4
...
Input DisrictGroup $ Month $ Count;
Datalines;
Cairns/Mulgrave(Dry) Jul96 0
Cairns/Mulgrave(Dry) Aug96 6
Cairns/Mulgrave(Dry) Sep96 0
NorthCairns Jul96 45.8
NorthCairns Aug96 9.6
NorthCairns Sep96 7.4
I attached my data.
This is my current code:
libname Example "~/my_courses/Homework/FinalHomework";
data Sugar;
infile '~/my_courses/Homework/FinalHomework/CaneData2.csv/' dsd firstobs=2;
input District $ DistrictGroup $ DistrictPosition $ SoilID SoilName $ Area Variety $ Ratoon $ Age HarvestMonth HarvestDuration TonnHect Fibre Sugar Jul96 Aug96 Sep96 Oct96 Nov96 Dec96 Jan97 Feb97 Mar97 Apr97 May97 Jun97 Jul97 Aug97 Sep97 Oct97 Nov97 Dec97;
;
run;
proc freq data=Sugar (obs=200);
tables DistrictGroup * Month / chisq expected cellchi2;
weight Count;
run;
Transposing data tutorials:
Wide to Long:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/
https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/
Looks like that's a proc transpose. See the tutorials linked above on how to wrangle your data.
@cassylovescats wrote:
If I changed it, how do I still format the code?
I have to run multiple different tests but am stuck on the code to get it to move all of the dates to one column and all of the numbers to a second column.
I am not very good at SAS and do not have guidance.
@cassylovescats wrote:
I am trying to do DistrictGroup vs. Monthly Rainfall with the amount of rainfall as the count.
Chi-Square tests are for counts, not amounts. So a Chi-Square test might be used to compare the number of days with rainfall, but not total rainfall.
If I changed it, how do I still format the code?
I have to run multiple different tests but am stuck on the code to get it to move all of the dates to one column and all of the numbers to a second column.
I am not very good at SAS and do not have guidance.
Transposing data tutorials:
Wide to Long:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/
https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/
Looks like that's a proc transpose. See the tutorials linked above on how to wrangle your data.
@cassylovescats wrote:
If I changed it, how do I still format the code?
I have to run multiple different tests but am stuck on the code to get it to move all of the dates to one column and all of the numbers to a second column.
I am not very good at SAS and do not have guidance.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.