BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Aexor
Lapis Lazuli | Level 10
Hello need help in below scenario 
 
I  have one map section , where user can provide any value 
map - 4, based on this value I  need to print below statement 
 
this value should print a statement like this 
array ma[4]/nosymbols;
ma[1]=1;
ma[2]=2;
ma[3]=3;
ma[4]=4;
 
suppose if  map - 3
 
array ma[3]/nosymbols;
ma[1]=1;
ma[2]=2;
ma[3]=3;
 
I need dynamic macro which will print these statement , as this part of one logic 
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You could make a MACRO to yield these statements.

%macro array(map=);
array ma[&map.]/nosymbols;
%do i=1 %to &map.;
ma[&i.]=&i.;
%end;
%mend;

%put %bquote(  %array(map=3)  ) ;
%put %bquote(  %array(map=4)  ) ;
94   %macro array(map=);
95   array ma[&map.]/nosymbols;
96   %do i=1 %to &map.;
97   ma[&i.]=&i.;
98   %end;
99   %mend;
100
101  %put %bquote(  %array(map=3)  ) ;
  array ma[3]/nosymbols; ma[1]=1; ma[2]=2; ma[3]=3;
102  %put %bquote(  %array(map=4)  ) ;
  array ma[4]/nosymbols; ma[1]=1; ma[2]=2; ma[3]=3; ma[4]=4;



 

View solution in original post

8 REPLIES 8
ballardw
Super User

I think you may need to go back a bit and describe what is going on. Write where? to a text file? data set? SAS Log? SAS Results window? SAS Output window? Word document? something else?

Where is the value "3" coming from? A macro variable? A data set? The result of a calculation?

 

And possibly which programming language you are discussing. I am not familiar with " /nosymbols" involved with arrays.

data_null__
Jade | Level 19

ARRAY array-name[dimensions</NOSYMBOLS> | <variable(s)> | <constant(s)> | <initial-values)>;

 

PROC FCMP

 


@ballardw wrote:

I think you may need to go back a bit and describe what is going on. Write where? to a text file? data set? Word document? something else?

Where is the value "3" coming from? A macro variable? A data set? The result of a calculation?

 

And possibly which programming language you are discussing. I am not familiar with " /nosymbols" involved with arrays.


 

Aexor
Lapis Lazuli | Level 10
Thanks for checking. yes 3 is coming from a macro variable . I got solution for this problem
data_null__
Jade | Level 19

This may be helpful, but you will have to figure how to adapt to your specific needs.

 

49         data _null_;
50            array ma[4] _temporary_ (11:14);
51            do i = 1 to dim(ma);
52               put ma[i]= +(-1) ';';
53               end;
54            run;

ma[1]=11;
ma[2]=12;
ma[3]=13;
ma[4]=14;
Ksharp
Super User

You could make a MACRO to yield these statements.

%macro array(map=);
array ma[&map.]/nosymbols;
%do i=1 %to &map.;
ma[&i.]=&i.;
%end;
%mend;

%put %bquote(  %array(map=3)  ) ;
%put %bquote(  %array(map=4)  ) ;
94   %macro array(map=);
95   array ma[&map.]/nosymbols;
96   %do i=1 %to &map.;
97   ma[&i.]=&i.;
98   %end;
99   %mend;
100
101  %put %bquote(  %array(map=3)  ) ;
  array ma[3]/nosymbols; ma[1]=1; ma[2]=2; ma[3]=3;
102  %put %bquote(  %array(map=4)  ) ;
  array ma[4]/nosymbols; ma[1]=1; ma[2]=2; ma[3]=3; ma[4]=4;



 

Aexor
Lapis Lazuli | Level 10
woww! awesome this is what I was looking . thank you
Tom
Super User Tom
Super User

What is a "map section"?

Aexor
Lapis Lazuli | Level 10
sorry I should have explained a bit more. I got solution. thanks for checking

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 8 replies
  • 1765 views
  • 5 likes
  • 5 in conversation