BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

 

data have;

length Group $50;

input Group $ _NAME_ $ Value ;

datalines;

 

WWWW AARP 1

TTTT BBRP 3

DDDD BBRP 2

EEEE BBRP 4

run;

 

I want to be able to tanspose the data and assign a label based on Value field as follows;

if the Value 1 '1_1_29'  If the Value is 2 then '2_30_59', if Value is 3 then '3_60_89'  if 4 then '4_90_119'  so I want to transpose and assign a label value based on the Value number. 

 

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Show us the desired output please.

Q1983
Lapis Lazuli | Level 10

data have;

length Group $50;

input Group $ _NAME_ $ Value ;

datalines;

 

WWWW AARP 1

TTTT BBRP 3

DDDD BBRP 2

EEEE BBRP 4

run;

 

I want to be able to tanspose the data and assign a label based on Value field as follows;

if the Value 1 '1_1_29'  If the Value is 2 then '2_30_59', if Value is 3 then '3_60_89'  if 4 then '4_90_119'  so I want to transpose and assign a label value based on the Value number.

 

So this is the desired result.

Group    Name     _1_1_29     _2_30_59    _3_60_89    _4_90_119   GrTotal

WWWW     AARP       1                                               1

TTTT             BBRP                                                                               3                                                      3

DDDD          BBRP                                                    2                                                                                   2

EEEE        BBRP                                                                                                                   4                       4

So essentially I am transposing the VALUE.  Another responder mentioned proc format

Tom
Super User Tom
Super User

Seems like a useless format and very,very strange variable names.

But if your values are nice simple integers then just use them as indexes into an array.

data want;
  set have ;
  array new _1_1_29     _2_30_59    _3_60_89    _4_90_119 ;
  new[Value] = Value ;
run;

Perhaps your real data has multiple observations per GROUP NAME?

data want;
do until(last._name_);
  set have ;
  by group _name_;
  array new _1_1_29     _2_30_59    _3_60_89    _4_90_119 ;
  new[Value] = Value ;
end;
  gr_total = sum(of new[*]);
run;
PGStats
Opal | Level 21

You could mean something like this:

 

proc format;
value myFormat
1 = '1_1_29'
2 = '2_30_59'
3 = '3_60_89'
4 = '4_90_119';
run;

data have;
length Group $50;
input Group $ _NAME_ $ Value;
format value myFormat.;
datalines;
WWWW AARP 1
TTTT BBRP 3
DDDD BBRP 2
EEEE BBRP 4
; 

proc transpose data=have out=want(drop=junk) name=junk;
by group notsorted;
var value;
id _name_;
run;

proc print data=want noobs; run;
                         Group      AARP        BBRP

                         WWWW     1_1_29             .
                         TTTT            .    3_60_89
                         DDDD            .    2_30_59
                         EEEE            .    4_90_119

Just a guess.

PG

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 844 views
  • 0 likes
  • 4 in conversation