BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cassylovescats
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.


 

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

@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.

PG
cassylovescats
Calcite | Level 5

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.

Reeza
Super User

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.


 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1448 views
  • 0 likes
  • 3 in conversation