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

Hello I have this data that I wish to createABC from Data AB  as follows:

 

Data A;

imput A B;

cards;

1   3

0   6

0   7

1  9

1  4

0  2

;

run;

Data ABC;

input A B C;

cards;

1   3   C=3+6+7+9+4+2=31

0  6   C=6

1  9   C=9+4+2=15

1  4   C=4+6

0   2  C=2

;

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Can be done with a double do loop:

 


data ABC;
do until(done);
    set a end=done;
    totSum + B;
    end;
done = 0;
do until(done);
    set a end=done;
    if A then C = totSum; else C = B;
    output;
    totSum + (-B);
    end;
keep A B C;
run;

proc print data=ABC noobs; run;
PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

Can be done with a double do loop:

 


data ABC;
do until(done);
    set a end=done;
    totSum + B;
    end;
done = 0;
do until(done);
    set a end=done;
    if A then C = totSum; else C = B;
    output;
    totSum + (-B);
    end;
keep A B C;
run;

proc print data=ABC noobs; run;
PG
MikeZdeb
Rhodochrosite | Level 12

Hi, no array but another way  ...

 

data a;
input a b @@;
datalines;
1 3 0 6 0 7 1 9 1 4 0 2
;

 

* place sum of values of variable B in macro variable &TOT;

proc sql noprint;
select sum(b) into :tot from a;
quit;

 

data want (keep=a b c);
set a;
cumb + lag(b);

c = a*(&tot-cumb) + ^a*b;
run;

 

data set WANT ...

Obs    a    b     c
 1     1    3    31
 2     0    6     6
 3     0    7     7
 4     1    9    15
 5     1    4     6
 6     0    2     2

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 704 views
  • 0 likes
  • 3 in conversation