BookmarkSubscribeRSS Feed
Filipvdr
Pyrite | Level 9

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?

4 REPLIES 4
art297
Opal | Level 21

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;

Filipvdr
Pyrite | Level 9

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

art297
Opal | Level 21

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.

Ksharp
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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