DATA Step, Macro, Functions and more

Array is truncating text values

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Array is truncating text values

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;

 


Accepted Solutions
Solution
‎11-22-2016 07:20 PM
Super User
Posts: 17,890

Re: Array is truncating text values

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


All Replies
Solution
‎11-22-2016 07:20 PM
Super User
Posts: 17,890

Re: Array is truncating text values

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;
Occasional Contributor
Posts: 11

Re: Array is truncating text values

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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