BookmarkSubscribeRSS Feed
rdum96
Calcite | Level 5

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?

 

 

1 REPLY 1
Tom
Super User Tom
Super User

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] ;
  ...

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1 reply
  • 294 views
  • 4 likes
  • 2 in conversation