BookmarkSubscribeRSS Feed
alorenzo
Calcite | Level 5

Hello SAS users,

 

After looking and looking, I can't find an efficient solution. My problem is I have to stay in a one and unique dataset.

The length of the array will change so it cannot be a number define.

 

The length of the array always be length1.

 

The only solution I found it's define a big number to have my 11 new variables.

Please find an example of code below:

 

data test ;
length1=11;
array psc00013_trans_amount{0:99999} 3.;
do i=1 to length1;
psc00013_trans_amount{i} = 0 ;
end;
run;

 

Thanks for your help, I'm totally lost.

2 REPLIES 2
ballardw
Super User

@alorenzo wrote:

Hello SAS users,

 

After looking and looking, I can't find an efficient solution. My problem is I have to stay in a one and unique dataset.

The length of the array will change so it cannot be a number define.

 

The length of the array always be length1.

 


You need to clarify what you mean by those two statments. Where does the value for length1 come from?

Is the purpose of this exercise to make a data set with one row of data of a specified number of variables all with value 0?

 

You may also be able to set the definition of the values to 0 at creation without the do loop.

 

Note that since you have set the lower bound on your array as 0 in the definition then the loop going from 1 to length1 will not assign a value to the zero element.

 

 

Ksharp
Super User
You can grab that magic number ,and apply it into ARRAY.

%let dsid=%sysfunc(open(sashelp.class));
%let nvar=%sysfunc(attrn(&dsid,nvars));
%let dsid=%sysfunc(close(&dsid));

%put &nvar ;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2 replies
  • 1480 views
  • 0 likes
  • 3 in conversation