BookmarkSubscribeRSS Feed
fabdu92
Obsidian | Level 7

Hi,

 

I have a table A and I want to duplicate each row into a table B, N times.

 

In table A Ifor each row have:

a date d

 

In table B i would like:

the date d + 1 month for each new row

a number m, calculated according to new date

 

So I do something like

data B;
set A;
do i=0 to N;
d = INTNX('month', d, +1, 'e');
m =...;
output;
end;
run;

But the issue with this, is that the original record from A is deleted and we have only date d+1 to d+n and no longer d.

I would like the programm to understand it need to keep the initial date too, and to calculate for this date the number m

 

Can you help me?

 

Thank you very much

2 REPLIES 2
Astounding
PROC Star

There should be a variety of ways to make this happen.  Here's one possibility:

 

data B;

set A;

do i=0 to N;

   m=...;

   output;

   d=...;

end;

m=...;

output;

run;

 

 

***** EDITED to move the first OUTPUT statement.

 

This assumes that all else is working properly, except for getting that first calculation into the output.

PGStats
Opal | Level 21

If you want both d and the new date in your output, you need two variables, right?

 

data B;
set A;
do i = 0 to N;
	newD = INTNX('month', d, i, 'END');
	m =...;
	output;
	end;
run;
PG

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
  • 704 views
  • 0 likes
  • 3 in conversation