How to analyze individual variables

Solved
Occasional Contributor
Posts: 8

How to analyze individual variables

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.

Accepted Solutions
Solution
‎04-15-2015 02:32 PM
Super User
Posts: 23,700

Re: How to analyze individual variables

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';

run;

OR

proc sort data=have;

by DineHall;

run;

proc freq DATA= HAVE;

BY DineHall;

run;

All Replies
Super User
Posts: 13,523

Re: How to analyze individual variables

proc freq data=datasetname;

tables var1 var2 /chisq;

run;

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

Occasional Contributor
Posts: 8

Re: How to analyze individual variables

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.

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?

Solution
‎04-15-2015 02:32 PM
Super User
Posts: 23,700

Re: How to analyze individual variables

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';

run;

OR

proc sort data=have;

by DineHall;

run;

proc freq DATA= HAVE;

BY DineHall;

run;

Occasional Contributor
Posts: 8

Re: How to analyze individual variables

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?

Super User
Posts: 23,700

Re: How to analyze individual variables

Try it?

Occasional Contributor
Posts: 8

Re: How to analyze individual variables

It worked! Thanks!

🔒 This topic is solved and locked.