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!!!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1845 views
  • 0 likes
  • 2 in conversation