BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Reeza
Super User

proc freq data=sashelp.class;

table sex*age/out=sample;

run;

proc transpose data=sample out=sample2 prefix=age;

by sex;

id age;

var count;

run;

SAS_new
Calcite | Level 5

Tried it multiple different ways and it does not appear to work. (including the count variable gave me the summarized data- thank you!)  But I am still getting multiple rows of the same race for different offenses.  So I have a row for school 123 for  23 Hispanic students under offense D.  I also have a row for school 123 for 15 Hispanc students under offense W.  Is there a way to produce 1 row for school 123 for HIspanic students that lists 15 under column offense W and 23 under column offense D?    Do you think I would need to do some type of merging in order to get a one row record per race?

art297
Opal | Level 21

sas_new: I haven't kept up with this thread, thus may be missing something, but it sure sounds like you are looking for something like:

data have;

  input (school student race offense) ($);

  cards;

A 12595 WHITE W1

A 1857 ASIAN D1

A 11589 BLACK V1

A 54812 WHITE W1

A 636884 HISPANIC D1

A 115887 HISPANIC D1

A 12595 WHITE W1

A 11589 BLACK V1

B 12595 WHITE W1

B 1857 ASIAN D1

B 11589 BLACK V1

B 54812 WHITE W1

B 636884 HISPANIC D1

B 115887 HISPANIC D1

B 12595 WHITE W1

B 11589 BLACK V1

;

ods output crosstabfreqs =  xtab;

Proc Freq data=have;

  tables school*race*offense/

         out=temp missprint;

run;

proc sort data=xtab;

  by school race offense;

run;

proc transpose data=xtab (where=

        (not(missing(offense) or missing(race))))

         out=want (drop=_:);

  var frequency;

  by school race;

  id offense;

run;

SAS_new
Calcite | Level 5


Thank you!  The results are exactly what I am looking for.   I am not familiar with how to read this code.  Can you help me interpret:

proc transpose data=xtab (where=

        (not(missing(offense) or missing(race))))

         out=want (drop=_:);

art297
Opal | Level 21

Proc transpose was used to bring each set of related records together on one record.  The original output file, from the ODS crosstabfreqs table includes summary lines that, in this case, would have missing values for the offense and race variables.  As such, I used a where statement to exclude those records.

The statement ended with an out=want (drop=_:); clause in order to omit/drop the automatic variables in the file that begin with an underscore as they weren't relevant to your desired output.

SAS_new
Calcite | Level 5

I tried to supress the noprint here on the Proc Freq code due to the large size of the dataset.  However, the crosstabfreqs code does not work with the 'noprint' option.  Is there a way around it?

ods output crosstabfreqs = xtab; run;

proc freq susp  noprint;

     tables schoolcode*race*offense/out=temp missprint; run;

proc sort data=xtab;

     by schoolcode*race*offense; run;

Reeza
Super User

You don't need the odsoutput, xtab dataset. Use the temp dataset instead, its basically the same thing.

I'm not sure why Art did both....in fact he gets rid of the extra data you get with the not missing functions in the next step.

Proc Freq data=have noprint;

  tables school*race*offense/

         out=temp sparse missprint;

run;

proc transpose data=temp (where=

        (not(missing(offense) or missing(race))))

         out=want (drop=_:);

  var count;

  by school race;

  id offense;

run;

SAS_new
Calcite | Level 5

Worked perfectly!  Thank you!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 22 replies
  • 1770 views
  • 4 likes
  • 4 in conversation