BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Agent1592
Pyrite | Level 9

Guys:

I have some data for two quarters. I am trying to create a want table like this one. Basically I am trying to get all the possible combinations of positive, negative and zero values for the two quarters. Can someone please help?

Q1Q2Percentage of  observations
+- 
++ 
+0 
-- 
-+ 
-0 
00 

 

data QTR1_QTR2;
  infile datalines dsd truncover;
  input q1:32. q2:32.;
datalines4;
0.0229132564,0.0838041414
0.106891732,0.0074999684
0.0523077125,-0.16913947
-0.038567431,-0.068585141
-0.085454507,-0.243917286
0.0890000313,0.4542936499
0.0110349708,0.083370712
-0.029292079,-0.064858472
0.0099681029,-0.036895711
-0.044827588,0.0155642022
0.0980392184,-0.030651339
0.1329480476,-0.029253897
-0.048689142,-0.044543457
0.0493506626,-0.026244339
0.0932343341,0.0101010271
0.0153109924,0.0172910492
-0.007617369,0.0033984659
-0.01668303,-0.019999972
-0.085653123,0.5458613398
0.1257996012,0.0046728942
-0.098692028,0.0074184272
-0.035149435,-0.073319685
-0.004424775,-0.016517244
0.0091439181,-0.031136883
-0.103247662,-0.003340726
-0.085603985,-0.011174274
-0.01265823,0.1142857201
-0.018691681,-0.021052613
0.0483871303,-0.068747026
-0.03592811,0.0762711838
0.0322581127,-0.03441676
-0.155797125,0.0526315302
-0.019607823,-0.111111035
-0.115241653,0.1209262308
-0.167777808,-0.094501742
0.0526315917,-0.195652182
0.0076775354,-0.013267065
0.0743801304,0.0957983665
-0.003337734,0.0406090978
0.0531119832,-0.044910138
-0.093476823,-0.026143835
0.0443655728,0.0069766844
0.2227414064,0.0838709378
-0.122536445,-0.157512908
0.0226337451,0.0292598979
0.0264391854,-0.093104137
0.0192138422,0.0019499369
-0.015653233,-0.033132504
-0.031857019,0.029294397
-0.002348574,0.0073886328
-0.010393421,0.0396806019
0.0072449318,-0.016953502
-0.025897032,0.0710188485
0.0162396527,-0.006883583
-0.058161403,0.0364925014
0.0279324718,-0.026210079
-0.00850093,0.0102726783
0.0014855785,-0.009168097
-0.013147191,-0.033698457
-0.018088938,0.0199586154
0.0253665383,-0.009128962
-0.008579102,0.0106737093
0.0254237281,0.0243902433
0.0161956251,-0.008353974
0.0301075587,0.0023753507
0.0011792273,0.0131826882
0.0965517395,0
0.2198887777,-0.052272707
-0.006122432,-0.062048489
0.0222310225,-0.099275499
-0.004782655,0.0269315951
0.178947362,-0.111919214
-0.01038965,0.0220640183
0.1296874839,-0.034274949
0.1213826582,-0.001717663
0.0096532162,-0.005925411
-0.010480034,-0.027166404
0.1508723906,-0.097846328
-0.007121461,0.0524017808
0.147407904,0.1645696171
0.0870989747,0.0188849336
-0.034640079,0.0290820163
0.0514352129,-0.05687266
-0.001493591,-0.005280889
-0.046075432,0.0207175256
0.0095069016,-0.055608193
0.0189642295,0.0388938768
-0.02785325,0.0141896625
-0.029350121,0.0227676751
-0.038080272,-0.026218913
-0.033831051,0.0337481215
0.0101404143,0.0059002192
-0.005680872,0.0048869832
0.0207583727,0.0062007108
0.0315314941,0.0019130049
0.0392450775,0.0227726593
-0.001592712,0.0225706998
0.0154698259,0.0430857292
0.0165745868,-0.012903227
-0.056369784,-0.010322571
;;;;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

First, create a format to perform the grouping:

 

proc format;

value neg0pos  low-<0 = '-'  0='0' 0-high='+';

run;

 

If there is the possibility of missing values in your data, you might want to account for those as well.

 

Then apply the format.  PROC FREQ does a good job counting:

 

proc freq data=have;

tables q1 * q2 / list missing;

format q1 q2 neg0pos.;

run;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

First, create a format to perform the grouping:

 

proc format;

value neg0pos  low-<0 = '-'  0='0' 0-high='+';

run;

 

If there is the possibility of missing values in your data, you might want to account for those as well.

 

Then apply the format.  PROC FREQ does a good job counting:

 

proc freq data=have;

tables q1 * q2 / list missing;

format q1 q2 neg0pos.;

run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 1869 views
  • 0 likes
  • 2 in conversation