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?
%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?
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;
%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?
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?
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: