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
- /
- SAS Procedures
- /
- How do I do this? Please help - newbie user

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

08-18-2013 12:23 PM

Hello all,

I use SAS 9.3 here and there for work stuff, I know some of the basics but I'm drawing a blank trying to figure out 2 things. Was really hoping for some help.

1) I have variable of just numbers from 0-100. I'd like to tell SAS to group them into 3 groups (0, 1-10, and 10+) so I can analyze using those three groups. How can I do this? I know it's probably something simple but I'm drawing a blank...

2) I have 10 variables, each with numbers varying from 1-5. I want to tell SAS to give me all the answers that were "1" or "2" or "3" overall and by year...how can I do that?

Everything else I need I was able to figure out one way or another except those...any help would be so appreciated. Thanks. I hope I was clear enough...

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

08-18-2013 01:09 PM

1)

/*assign group number based on numeric value*/

data answer1;

set one;

if number_var =0 then group_no=1;

else if number_var le 10 then group_no=2;

else group_no=3;

run;

/*sample frequency analysis*/

proc freq data=answer1;

tables group_no;

run;

2)

/*simple subsetting of numeric variable. */

data answer2;

set two;

where number_var in (1,2,3);

run;

/*print new dataset, year information should have been kept from original dataset,*/

proc print data=answer2;

run;

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

08-18-2013 02:36 PM

First one I got down perfect thanks to you. THANK YOU!!

I still need a little bit of help on the second. I might not have been clear enough.

I have a dataset called surveys2.

Within that dataset I have 10 variables, each a separate question. (the variables are named q1 q2 q3 ...q10).

Each questions has a 343 rows, in each row is a number 1-5 or 8 (people's answer to the question)

I want to sum up all the answers of 1, 2, 3, 4 ,5 or 8 separately and break them out by year.

For eg: How many ppl answered three in total or in 2010 for each question and overall.

How can I do that?

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

08-18-2013 04:24 PM

As I understand survays2 has 11 variables and 343 observations, the first 10 variables have numeric values within (1, 2, 3, 4, 5, 8), (I assume 8 implies the person (observation) didn't answer atall). The last variable is the year.

Q: How many ppl answered three in total or in 2010 for each question and overall.

I am tying to make sense of this question; are you asking how many people answered question the in 2010, and answered question 3 in all time?

If so here is the answer:

/* how did people answer question 3 in 2010> */

proc freq data=survay2(where=(year=2010));

tables q3;

run;

/* how did people answer question 3 in over all years? */

proc freq data=survay2;

tables q3*year;

run;

This should give you a cross-tabulation that provides a yearly breakdown of people's answers.

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

08-18-2013 05:14 PM

Change your data format to the following structure:

Person Question Year Response

You can use proc transpose to change the data format.

SAS Learning Module: How to reshape data wide to long using proc transpose

Then you can use Proc Freq to analyze your data easily.

EG.

proc freq data=have;

table year*response/out=summary1;

run;

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

08-18-2013 05:26 PM

You can use one of the CAT functions to count how many responses were 1,2,3,4,5 or 8 in each row. Something like:

Data sum_response ;

set survey2;

count1 = countc(catt(of q1-q10), '1');

count2 = countc(catt(of q1-q10), '2');

etc . . .

count8 = countc(catt(of q1-q10), '8');

run;

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

08-19-2013 11:15 AM

1) I have variable of just numbers from 0-100. I'd like to tell SAS to group them into 3 groups (0, 1-10, and 10+) so I can analyze using those three groups. How can I do this? I know it's probably something simple but I'm drawing a blank...

Another way to analyze things in groups without having to add anything to your data is custom formats.

Try:

Proc format library=work;

value mygroup

0 = ' 0'

1 - 10 = ' 1 to 10'

11-100='11 to 100'

;

run;

proc freq data= yourdatasetname;

tables yourvariablename;

format yourvariablename mygroup. ;

run;

The text assosiated with the format can be pretty much what you want.