turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- How to analyze individual variables

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-15-2015 11:42 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-15-2015 02:32 PM

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;

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-15-2015 01:11 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-15-2015 02:20 PM

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?

Solution

04-15-2015
02:32 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-15-2015 02:32 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-15-2015 09:48 PM

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2015 12:03 PM

Try it?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2015 12:29 PM

It worked! Thanks!