BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
acairns
Fluorite | Level 6

I am using an array to count the number of associates.  The value of assoc_nm_2 is formatted as $80.  however, when the array is complete it truncates the values of assoc_nm_2 to $8.  Is there a way to maintain the length of that variable?  I tried a format statement but that bombed. 

 

data nineteen_2 (drop=i j assoc_id_nb assoc_subtyp_cd_2 assoc_nm_2 reg_nb_assoc);

set nineteen;

by PRMRY_BUS_FUNC_NB;

 

array af_id{%eval(&max_af)} af_id1 - af_id%eval(&max_af);

array af_typ_cd{%eval(&max_af)} af_typ_cd1 - af_typ_cd%eval(&max_af);

array af_nm{%eval(&max_af)} $ af_nm1 - af_nm%eval(&max_af);

array af_reg_nb{%eval(&max_af)} $ af_reg_nb1 - af_reg_nb%eval(&max_af);

retain af_id1 - af_id%eval(&max_af) af_typ_cd1 - af_typ_cd%eval(&max_af) af_nm1 - af_nm%eval(&max_af) af_reg_nb1 - af_reg_nb%eval(&max_af);

if first.PRMRY_BUS_FUNC_NB then do;

i=0;

do j=1 to %eval(&max_af);

af_id(j)=.;

af_typ_cd(j)=.;

af_nm(j)='';

af_reg_nb(j)='';

end;

end;

i+1;

 

af_id{i}=assoc_id_nb;

af_typ_cd{i}=assoc_subtyp_cd_2;

af_nm{i}=assoc_nm_2;

af_reg_nb{i}=reg_nb_assoc;

 

if last.PRMRY_BUS_FUNC_NB;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

If you don't specify a length I think it defaults to 8. 

 

You can also probably simplify your code as follows - note that I set the array to a length of 12.

You can remove the %eval if you don't have a calculation and use the * to denote length so then SAS determines it automatically based on the list size. 

 

 

data nineteen_2 (drop=i j assoc_id_nb assoc_subtyp_cd_2 assoc_nm_2 reg_nb_assoc);
set nineteen;
by PRMRY_BUS_FUNC_NB;
 
array af_id{*} af_id1 - af_id&max_af;
array af_typ_cd{*} af_typ_cd1 - af_typ_cd&max_af;
array af_nm{*} $12 af_nm1 - af_nm&max_af;
array af_reg_nb{*} $12 af_reg_nb1 - af_reg_nb&max_af;

View solution in original post

2 REPLIES 2
Reeza
Super User

If you don't specify a length I think it defaults to 8. 

 

You can also probably simplify your code as follows - note that I set the array to a length of 12.

You can remove the %eval if you don't have a calculation and use the * to denote length so then SAS determines it automatically based on the list size. 

 

 

data nineteen_2 (drop=i j assoc_id_nb assoc_subtyp_cd_2 assoc_nm_2 reg_nb_assoc);
set nineteen;
by PRMRY_BUS_FUNC_NB;
 
array af_id{*} af_id1 - af_id&max_af;
array af_typ_cd{*} af_typ_cd1 - af_typ_cd&max_af;
array af_nm{*} $12 af_nm1 - af_nm&max_af;
array af_reg_nb{*} $12 af_reg_nb1 - af_reg_nb&max_af;
acairns
Fluorite | Level 6

That works perfect!  I knew it had to be something simple like that.  Thank you for your help!!!!

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
  • 1232 views
  • 0 likes
  • 2 in conversation