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

Hi, I wrote a big macro to execute a do loop. While in the loop, I want to write another loop to do a job. I am not familiar how to do this. In the second loop, I have a dataset "have" to start with. In the dataset, I have four variables, firm, assets, parm1 and parm2. It looks like below

dataset have

firm          asset          parm1          parm2

01               50               0.2               10

02               30               0.2               15

03               10               0.1               20

...

Firms are unique. For each firm, I want to create 10 observations. Each observation is equal to parm1**(i)*(asset-parm2). For example, for firm 01, p1(the first observation) = 0.2**(1) * (50-10), p2(the second obs) = 0.2**(2)*(50-10), ... p10 = 0.2**(10)*(50-10).

So the dataset I want to obtain is like

firm          p          asset          parm1          parm2

01          p1          50               0.2               10

01          p2          50               0.2               10

...

01          p10 .....

02          p1

...

...

Please advise how to write a do loop either in proc sql or in data to achieve this purpose.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Does not sound like macro has anything to do with want you want. This can be done with a simple DO loop in a data step.

data want ;

  set have ;

  do i=1 to 10 ;

     p=parm1**(i)*(asset-parm2);

      output;

  end;

run;

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

I believe it would help if you could provide us with a bit more background and eventually also with your macro. Not sure at all what you're trying to do here but may be Proc Plan could be interesting for you.

Tom
Super User Tom
Super User

Does not sound like macro has anything to do with want you want. This can be done with a simple DO loop in a data step.

data want ;

  set have ;

  do i=1 to 10 ;

     p=parm1**(i)*(asset-parm2);

      output;

  end;

run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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