Help using Base SAS procedures

creating array for each row based on a count

Reply
Regular Contributor
Posts: 237

creating array for each row based on a count

options symbolgen mlogic mprint;

data &InputParam/*(keep = Info Wafers_1 CO1-CO10)*/;

format Info Wafers_1 CO1-CO10;

set Recipe_transp;

Nr = countc(COL1,'+');

CALL SYMPUT('Nummer', Nr);

array CO{10} $50.;

  do L = 1 to Nr;

  CO{L} = scan(COL1,L,'+');

end;

Info = "&InputParam";

run;

what i want to do is replace the CO{10} by CO{Nr} but i dont know how?

PROC Star
Posts: 7,474

creating array for each row based on a count

Not quite sure what you are trying to do.  Does it approximately something like the following?:

data have;

  informat COL1 $30.;

  input COL1;

  cards;

+3+4+5

+2

+1+2+3+4+5

;

proc sql noprint;

  select max(countc(COL1,'+')) into : nummer

    from have;

quit;

data want;

  set have;

  array CO{&nummer.} $50.;

  L=1;

  do while (scan(COL1,L,'+') ne "");

    CO{L} = scan(COL1,L,'+');

          L+1;

  end;

run;

Regular Contributor
Posts: 237

creating array for each row based on a count

well i gues it solves my problem, as i want to make sure of the exact number of CO (columns). But after all it is a dataset so the maximum is OK for this.

But is there a way to make a different Nummer for each single row in my dataset because now i always count to the max

PROC Star
Posts: 7,474

creating array for each row based on a count

As long as you initially set the array high enough to capture all values, there are numerous ways to limit the number of iterations.

For example, the method I used, the method you originall used, a slight variant of that method:

do l=1 to countc(COL1,'+');

and many others.

Two things to note: the array dimensions are set just once and you can't access a macro variable you create from within the datastep it is created.

Super User
Posts: 10,035

creating array for each row based on a count

Just write as

array CO{nr} $50.;

cann't it work?

or use a data _null_ before your data step to make a macro variable "call symputx(....)",

then use this macro variable to instead of 10.

Ksharp

Ask a Question
Discussion stats
  • 4 replies
  • 153 views
  • 0 likes
  • 3 in conversation