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

Hi,

Maybe someone can help me with my case, I have one obs date '20APR2020'  in table week0 and i need to create one table with 7 obs, '20APR2020','21APR2020','22APR2020' etc.

i try this but i doesn't work correctly

%macro sqlloop(start,end);
PROC SQL;

%DO i=&start. %TO &end.;
/* %let j=%eval(&i+1);*/
CREATE TABLE week%eval(&i+1) as

SELECT

intnx('day',day,&i.) as day format=date9.
FROM week&i. ;
/*union */
/*select * from ; */
%END;
QUIT;
%mend;

%sqlloop(start=0, end=7)

 

I need one table with values (for start I have only one date '20APR2020'):

'20APR2020'

'21APR2020'

'22APR2020'

'23APR2020'

.....

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Are there any other variables involved? If so, what values should they have for the added rows?

Is your "date" a character variable or a SAS date value with the date9 format assigned? It isn't really clear.

 

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the <> to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.

 

Often the data step is much easier to do something like add additional records based on an incrementing rule.

Below code shows creating 7 observation from scratch and adding 6 observations.

data want;
  day='20APR2020'd;
  output;
  do i=1 to 6;
   day = intnx('day',day,1);
   output;
  end;
  format day date9.;
  drop i;
run;
/* IF you actually have a dataset named week0
  with a date valued variable named day:
*/

data want;
  set week0;
  output;
  do i=1 to 6;
   day = intnx('day',day,1);
   output;
  end;
  format day date9.;
  drop i;
run;

 

View solution in original post

2 REPLIES 2
ballardw
Super User

Are there any other variables involved? If so, what values should they have for the added rows?

Is your "date" a character variable or a SAS date value with the date9 format assigned? It isn't really clear.

 

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the <> to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.

 

Often the data step is much easier to do something like add additional records based on an incrementing rule.

Below code shows creating 7 observation from scratch and adding 6 observations.

data want;
  day='20APR2020'd;
  output;
  do i=1 to 6;
   day = intnx('day',day,1);
   output;
  end;
  format day date9.;
  drop i;
run;
/* IF you actually have a dataset named week0
  with a date valued variable named day:
*/

data want;
  set week0;
  output;
  do i=1 to 6;
   day = intnx('day',day,1);
   output;
  end;
  format day date9.;
  drop i;
run;

 

Irena_ik
Fluorite | Level 6

It's exactly what I need!

Thank You very much 🙂

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
  • 2 replies
  • 1112 views
  • 1 like
  • 2 in conversation