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

Hi,

I would like to know how to automatically determine the number of items in & type(=26) instead of declaring 26 in the below script....
Just a very simple example:

 

%let type= A B C D E F G H I J K L M N O P R S T U V W X Y Z ;

data _NULL_;

do i = 1 to 26;   <---- this value of 25 is what I would like to automate when I change &type.

put Number=i ;

end;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisBrooks
Ammonite | Level 13

Assuming they're always space separated then the countw function should do the trick like so

 

%let type= A B C D E F G H I J K L M N O P R S T U V W X Y Z;
data _NULL_;
do i = 1 to countw("&type");  
put Number=i ;
end;
run;

View solution in original post

3 REPLIES 3
ChrisBrooks
Ammonite | Level 13

Assuming they're always space separated then the countw function should do the trick like so

 

%let type= A B C D E F G H I J K L M N O P R S T U V W X Y Z;
data _NULL_;
do i = 1 to countw("&type");  
put Number=i ;
end;
run;
Jiawenabby8
Fluorite | Level 6

Your links are super helpful. Thanks so much!

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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