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

data CP;

input t ;

cards;

2

3

2

4

I want  to create variable sum where sum add the number from n and below like this:

2  Sum=2+2+3+2+4

2  Sum=  2+3+2+4

3 Sum=  3+2+4

Sum=  2+4

4  Sum=4


2) And how Do I do this. I want to add 2, 2(2) t the terms in t as I go dowm. Creating variable m.


data AA;

input t;

cards ;

1

1

1

1


to

data AA;

input t m;

cards ;

1  1+2

1   1+2(2)

1  1+3(2)

1  1+4(2)


Thanks


1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

I'm confused!  I thought the code I suggested DID preserve the order in both cases.

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

data CP;

  input t;

  recnum=_n_;

cards;

2

2

3

2

4

;

proc sort data=cp out=aa;

   by descending recnum;

run;

data aa;

  set aa;

  sum+t;

run;

proc sort data=aa (drop=recnum);

  by descending sum;

run;

data bb;

  input t;

  m=t+_n_*2;

  cards ;

1

1

1

1

;

desireatem
Pyrite | Level 9

Thanks thanks a lot can I do I preserve the order?

art297
Opal | Level 21

I'm confused!  I thought the code I suggested DID preserve the order in both cases.

desireatem
Pyrite | Level 9

The second code is good, this is the output of the first

The SAS System

      
1454
2246
3339
42211
52113

desireatem
Pyrite | Level 9

you are correct. Thanks

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
  • 5 replies
  • 541 views
  • 1 like
  • 2 in conversation