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

I have a large data set like this :

NAME  MONEY  NB  NUMBER    CLASS

John      300        1         4           ab_4_ab_1
Max       250        2         5           be_2_be_1
Matt      1520       2          2          da_3_da_2

I use this code :

data want;
set have;
if nb = 2
then do;
  money = money / number;
  nb = nb / 2;
  output;
end;
output;
drop number;
run;

to get this data :

 

NAME    MONEY   NB     CLASS

John       300         1       ab_4_ab_1
Max         50          1       be_2_be_1
Max         50          1       be_2_be_1
Matt        760        1       da_3_da_2
Matt        760        1       da_3_da_2

 

I want to assign to the first duplicate observation the first four character of CLASS and the last four character of CLASS for the second duplicate observation. I mean how get  this :

NAME    MONEY   NB   CLASS

John       300         1      ab_4_ab_1
Max         50          1       be_2
Max         50          1       be_1
Matt        760        1       da_3
Matt        760        1       da_2

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21
data want;
set have;
if nb = 2 then do;
  money = money / number;
  nb = nb / 2;
  c = class;
  class = substr(c,1,4);
  output;
  class = substr(c,6,4);
  output;
  end;
else output;
drop number c;
run;
PG

View solution in original post

1 REPLY 1
PGStats
Opal | Level 21
data want;
set have;
if nb = 2 then do;
  money = money / number;
  nb = nb / 2;
  c = class;
  class = substr(c,1,4);
  output;
  class = substr(c,6,4);
  output;
  end;
else output;
drop number c;
run;
PG

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!

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
  • 1 reply
  • 309 views
  • 1 like
  • 2 in conversation