BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Rakeon
Quartz | Level 8

Hi,

I would like to create a table with 99 rows and 99 columns automatically.

With this macros I'm able to create 99 row automatically.:

%MACRO CALCULATE(COLUMN=);	
	data &column;
		do i=1 to 99;
			output;
		end;
		rename i=freq_range;
	run;
%MEND;

%CALCULATE(COLUMN=_1);

but I haven't any idea how to create 99 columns automatically.

Is there a way?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
%MACRO CALCULATE(COLUMN=);	
	data want;
               array var(&column) _1-_&column.;
		do i=1 to &column;
			output;
		end;
	run;
%MEND;

%CALCULATE(COLUMN=99);

That macro also renames and does some other things. 

 

I suspect this is an XY problem, what are you actually trying to accomplish?

Otherwise, I've included an example above where you can create a set of variables, _1- _99 with 99 number of rows as well. To modify the size, change the parameter to the macro.

 


@Rakeon wrote:

Hi,

I would like to create a table with 99 rows and 99 columns automatically.

With this macros I'm able to create 99 row automatically.:

%MACRO CALCULATE(COLUMN=);	
	data &column;
		do i=1 to 99;
			output;
		end;
		rename i=freq_range;
	run;
%MEND;

%CALCULATE(COLUMN=_1);

but I haven't any idea how to create 99 columns automatically.

Is there a way?


 

 

 

 

View solution in original post

4 REPLIES 4
ballardw
Super User

Details about the "columns" would be helpful.

The easiest way to create a multiple variables of the same type is an array statement. This would create 99 variables named var1 through var99 that are numeric. If you need different types of variables, such as a mix of character and numeric then you need to specify more information.

%MACRO CALCULATE(COLUMN=);	
	data &column;
                array var(99);
		do i=1 to 99;
			output;
		end;
		rename i=freq_range;
	run;
%MEND;
Reeza
Super User
%MACRO CALCULATE(COLUMN=);	
	data want;
               array var(&column) _1-_&column.;
		do i=1 to &column;
			output;
		end;
	run;
%MEND;

%CALCULATE(COLUMN=99);

That macro also renames and does some other things. 

 

I suspect this is an XY problem, what are you actually trying to accomplish?

Otherwise, I've included an example above where you can create a set of variables, _1- _99 with 99 number of rows as well. To modify the size, change the parameter to the macro.

 


@Rakeon wrote:

Hi,

I would like to create a table with 99 rows and 99 columns automatically.

With this macros I'm able to create 99 row automatically.:

%MACRO CALCULATE(COLUMN=);	
	data &column;
		do i=1 to 99;
			output;
		end;
		rename i=freq_range;
	run;
%MEND;

%CALCULATE(COLUMN=_1);

but I haven't any idea how to create 99 columns automatically.

Is there a way?


 

 

 

 

Tom
Super User Tom
Super User

No macro is needed.

Here is code to create a dataset with 99 VARIABLES and 99 OBSERVATIONS.

data want;
   length var1-var99 8;
   do _n_=1 to 99;
      output;
   end;
run;

Of course all 99*99 values are missing.

 

What variables do you want to create?  What names should the variable have?  What type of variables should they be? Should they all be numeric?  Character? If character should they all be the same length?

What values do you want in the 99 different observations?  Or do you want 99 observations that are all exactly the same?

 

Rakeon
Quartz | Level 8
Hi,
thanks also what have you done is working!!!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 638 views
  • 2 likes
  • 4 in conversation