BookmarkSubscribeRSS Feed
rrpking
Calcite | Level 5

 I was able to get some help and get this far: 

 

data want;
do year = &FirstYear to &CurrentYr;
output;
end;
retain m_03 0;
retain m_06 0;
retain m_09 0;
run;

 

However, let's say I want my table to go to m_225, how would I do that?

 

I thought I could use a do loop but it ended up giving me a weird table with the variable I used for my counter as a table column.

 

Thanks.

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

??

Sorry your post makes no sense.  Do you want new variables which have m_xyz up to 225?  If so then an array, however there would be better modelling techniques than 225 variables.

The retain seems to be a bit pointless, just creating 3 variables with the same data.  And the do just creates a bunch of rows.  Not sure what you expect us to do with this. 

Post test data in the form of a datastep

Show what the output should look like

Explain what the logic between the two is.

PaigeMiller
Diamond | Level 26

You've got macro variables (&FirstYear and &CurrentYr) that don't seem to relate to anything else in the program. You've got a do loop that doesn't seem to relate to the retain statements. In short, we don't know what you are trying to do, and the code you have provided doesn't seem to make any sense. You tried something with this code (or was it some other code?) and the result was "weird", but we have no idea what that means either.

 

So, please explain what you would like to do in words, and not in code. We need a clear and complete explanation, written so that your high school English teacher would give you a grade of A+. And then, we can probably provide code that will get the job done.

--
Paige Miller
ballardw
Super User
array m_{255}  (255*0);

If the variables do not exist an array statement such as this will make 255 variables, m_1 to m_255. The (255*0) is not multiplication but is the instruction to set all 255 varaibles to the value of 0 when the array is populated.

 

 

Still no example of how this data is to be used. Creating that many zero valued variables often indicates that another approach may well be indicated.

Astounding
PROC Star

You can see a follow-up post to your original, with a good solution for this:

 

https://communities.sas.com/t5/Base-SAS-Programming/Create-table-with-incremental-rows-and-years-for...

 

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
  • 4 replies
  • 1790 views
  • 0 likes
  • 5 in conversation