BookmarkSubscribeRSS Feed
shru
Calcite | Level 5

Hi,

My code is

data text;

set data1;

if nobs=1 then do;

b=0;

v=0;

end;

b=b+bal;

v=v+val;

run;

Where my data1 datset contains a column nobs like below

nobs

2     

3    

4

5

6

7

and i want result like

nobs bal val

1      2    3

2     3    5

3     5     8

likewise

the code should produce the cumulative values ,but i am getting the missing value when i run the above code

can anyone let me know is there any other way to do or y is this failing?

Thanks

3 REPLIES 3
Doc_Duke
Rhodochrosite | Level 12

I don't understand the result that you are trying to get, but there are several obvious problems that will yield missing data:

1) you need to read about the RETAIN statement for DATA step accumulation.

2) nobs never takes on the value '1' so the first DO is never executed.

3) bal and val are not in the input data set, so they start as missings.

Doc Muhlbaier

Duke

PaigeMiller
Diamond | Level 26

data text;

set data1;

b+bal;

v+val;

run;

--
Paige Miller
Linlin
Lapis Lazuli | Level 10

try changing

b=b+bal;

v=v+val;

to

b+bal;

v+val;

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
  • 3 replies
  • 754 views
  • 0 likes
  • 4 in conversation