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

Data test;

length var1 $10 var2 $ 20 var3 $25;

run;

Data test;

set test;

var1="";

var2="";

var3="";

%let columnlength=round(ranuni(0)*25,1);

 

/*25 represent the column length of var3. The question is how to get this value to put it into this function. I would like to do the same for each variable*/

 

do i=1 to &ColumnLength.;

var3=catt(var3,byte(int(97+26*ranuni(0))));

end;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use an array in your datastep, then use the vlength function to get the length and the call symputx function to create the macro variable (although why, and why the ranuni is another question).

data test;
  set test;
  array var{3};
  do i=1 to 3;
    call symputx(cats('var',put(i,best.)),vlength(var{i}));
  end;
run;

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use an array in your datastep, then use the vlength function to get the length and the call symputx function to create the macro variable (although why, and why the ranuni is another question).

data test;
  set test;
  array var{3};
  do i=1 to 3;
    call symputx(cats('var',put(i,best.)),vlength(var{i}));
  end;
run;
ballardw
Super User

I would guess the OP is attempting to get a random lower case letter if working on an ASCII system.

alepage
Barite | Level 11

Very simple!

Thank a lot

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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