Hi,
I have a dataset with existing variables category_1-category_n. I want to create another array 'price' being price_1-price_n. Depending on the which version of the data I'm using the value of 'n' can change.
I tried this:
array cats $ category: ;
array price {dim(cats)} price:;
which did not work. Would there be a way to achieve this?
To define new variables you need to know how many to create BEFORE that data step even starts running so there is no way the syntax you proposed could work (even if SAS modified the language to allow it).
You might try this method to create a macro variable first and then use that in the data step.
data _null_;
if 0 set have ;
array cats category: ;
call symputx('nvars',dim(cats));
stop;
run;
data want;
set have ;
array cats category: ;
array price [&nvars] ;
...
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!
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.