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

I am trying to perform basic chi square and logistic regression with two separate variables (Var1 and Var2) , but I cannot seem to figure out the coding to perform the analysis for just Var1 or just Var2. Do I need to create 2 separate excel documents to analyze the two variables separately? I feel like there is an easier way to perform the analysis. In other SAS programs, I simply used an "If-then-delete" statement, but that statement isn't working with the SAS University Edition. Can anyone help me with this coding? Hopefully this makes sense.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I'm not 100% sure what you're doing is valid but here's how you would technically do it. You also don't include all your code so its hard to see how you've pieced things together.


Your IF statement is correct, if it was included in a data step but not in the proc freq.


Assuming your data set is called HAVE


proc freq DATA= HAVE;

WHERE DineHall='DineHal1';

tables (Salads1 NEplates)*DineHall/chisq;

run;


OR


proc sort data=have;

by DineHall;

run;


proc freq DATA= HAVE;

BY DineHall;

tables (Salads1 NEplates)/chisq;

run;

View solution in original post

6 REPLIES 6
ballardw
Super User

I would start with

proc freq data=datasetname;

tables var1 var2 /chisq;

run;

And I have no idea why Excel would enter the situation at all.

mpatts
Calcite | Level 5

I might have worded my question poorly. I am trying to perform chi square between variables in two separate categories. The categories are DineHal1 and DineHal2. I want to do the chi square analysis between Salads1 and NEplates ONLY under DineHall1. Then I want to do the same chi square analysis for DineHal2. The problem I am running into is that the data for DineHal1 and DineHal2 are combining and the chi square analysis is looking at all of the data for Salads1 and NEplates for both DineHal1 and DineHal2.

DineHall          Salads1        NEplates

DineHal1             1                    3

DineHal1             0                    2

DineHal1             1                    1

DineHal1             1                    2

DineHal1             0                    1

DineHal2             1                    3

DineHal2             0                    3

DineHal2             0                    1

DineHal2             0                    1

DineHal2             1                    2

This is roughly how the data looks in the excel sheet if that helps explain my situation any better.

I have previously coded:

proc freq; tables (Salads1 NEplates)*DineHall/chisq; run;

The program runs the analysis, and it looks at DineHal1 and DineHal2 combined. So to look at chi square for just DineHal1, I tried this coding:

If DineHall="DineHal2" then delete; run;

When I run that analysis, it comes up with multiple errors.

How do I look solely at the variables under DineHal1 or DineHal2?

Reeza
Super User

I'm not 100% sure what you're doing is valid but here's how you would technically do it. You also don't include all your code so its hard to see how you've pieced things together.


Your IF statement is correct, if it was included in a data step but not in the proc freq.


Assuming your data set is called HAVE


proc freq DATA= HAVE;

WHERE DineHall='DineHal1';

tables (Salads1 NEplates)*DineHall/chisq;

run;


OR


proc sort data=have;

by DineHall;

run;


proc freq DATA= HAVE;

BY DineHall;

tables (Salads1 NEplates)/chisq;

run;

mpatts
Calcite | Level 5

This is all of the coding I have thus far:

proc import datafile="/folders/myfolders/Trayless/DHDataSAS.xlsx"

                    out=WORK.Analysis

                    DBMS=XLSX

                    Replace;

/*

proc print data=WORK.Analysis; run;

*/

proc freq; tables (Salads1 NEplates)*DineHall/chisq; run;


Should the coding mentioned in the above comment still work?

Reeza
Super User

Try it?

mpatts
Calcite | Level 5

It worked! Thanks!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 672 views
  • 1 like
  • 3 in conversation