BookmarkSubscribeRSS Feed
CFF
Calcite | Level 5 CFF
Calcite | Level 5

Hi

I have 1 variabel A. I need to create a new variabel B thats i created through the retain function. For the first observation must B must be equal to 1.

For all the other values B=1-B*A - where B is the retained result.

As an example:

Data have:

A:

0,5

0,5

0,5

Data want

A:       B

0,5     1

0,5     0,5 (calculated as: 1-1*0,5)

0,5     0,75 (calculated as: 1-0,5*0,5)

Best regards

3 REPLIES 3
ballardw
Super User

data want;

     set have;

     retain b 1;

     if _n_ > 1 then b= 1- b*a;

run;

KrisNori
Obsidian | Level 7

DATA A10Aug2015_1;

  retain B 1;

  INPUT A;

  OUTPUT;

  B=1-B*A;

DATALINES;

0.5

0.5

0.5

;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am not clear on what the dataset A is for, it doesn't add anything to the mix.  Adjust the do loop for number of iterations:

data want (drop=i);

  retain b 1;

  do i=1 to 5;

    b=1 - (b * 0.5);

    output;

  end;

run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1420 views
  • 0 likes
  • 4 in conversation