Help using Base SAS procedures

help with creating a dataset or table

Reply
N/A
Posts: 0

help with creating a dataset or table

I have data which contains list of people with their sex, age and the country they moved from and the state they moved to:

NAME AGE SEX FROM TO
John Smith 25 M Canada Maryland
Mary Fernandez 4 F Spain Illinois
etc.

I need 2 datasets (one for males and one for females) for each US state:

In these datasets there should be numbers of people moving to the particular state totalled per foreign country by sex and age.

For example I should be able to look at the Maryland (male) table and see that 12 men aged 36 moved there from Canada for example.

Anyone have any idea how I can do this or even get started? I am not a programmer and I am stuck. Thanks!

mu Message was edited by: michaelaunsworth
Trusted Advisor
Posts: 2,116

Re: help with creating a dataset or table

Posted in reply to deleted_user
Use PROC FREQ and output the table to a dataset, then split the dataset (or run FREQ twice, once for men and once for women; men shown below):

PROC FREQ DATA=mydata(WHERE=(sex='M'));
TABLES to*from*age/out=males;
RUN;
N/A
Posts: 0

Re: help with creating a dataset or table

Thanks Doc, the HTML output is exactly what I was looking for

Other than cutting and pasting, is there any way of getting the tables in the HTML output into either a SAS dataset or an excel dataset?
Contributor
Posts: 43

Re: help with creating a dataset or table

Posted in reply to deleted_user
Hi,
in my view first prepare the dataset first ( sdata).
later

data maledataset femaledataset;
set sdata;
if gender eq "F" then output femaledataset;
else if gender eq "M" then output maledataset;
run;

/* it would create one for male and another for female.*/

hope it may help you
Trusted Advisor
Posts: 2,116

Re: help with creating a dataset or table

Posted in reply to deleted_user
One approach to getting the output into a dataset or export is to use ODS. You can create/output/manipulate pretty much anything you can print from a procedure. You'll need to read a good bit of documentation or BBUs to become proficient, but the results can be quite useful.
Ask a Question
Discussion stats
  • 4 replies
  • 78 views
  • 0 likes
  • 3 in conversation