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] ;
...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.