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