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

data have;

input name$30.;
cards;
sai,priya,kunta,reddy,mskhdk
sgrav,mahesg,pitre,pedda
kiran,mami,chinna
ajay,kumar
divya
;
run;

 

For this data  first i need use countw(name),then we will get the values of higher word name i.e 5 from our data

then i will use array.. like below

 

data want;

set have;

array kiran(5) $ name1-name5;

do i =1 to 5;

kiran(i) =scan(name,i,',');

end;

run;

 

By doing this we will get 

name1 name2.............name5

sai        priya...............mskhdk

.

.

.

like that we will get exact data;

 

by using countw function we can find maxnumber of words then have to follow array

But here i dont know how many maxwords are their in variable i want above data using array only;

i what the above output in single data step..

many thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@Saikiran_Mamidi wrote:

 

by using countw function we can find maxnumber of words then have to follow array

But here i dont know how many maxwords are their in variable i want above data using array only;

i what the above output in single data step..

 


I consider these restrictions to be inappropriate and unnecessary, and so I don't see why you can't do it using two data steps, or not using arrays.

 

The obvious method is to pass through the data once, obtain the maximum number of words in a given record. Then in the second data step you know how big to make the array. Now if the data set is so HUGE that passing through it twice is not a good idea, then you are stuck with solutions that will be inefficient anyway, such as setting the array size to some large number (such as 20) even when there may only be 6 names in a row, but you won't know that 6 is the number until you pass through the data, and you can't take the risk of having an array size that is too small.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

@Saikiran_Mamidi wrote:

 

by using countw function we can find maxnumber of words then have to follow array

But here i dont know how many maxwords are their in variable i want above data using array only;

i what the above output in single data step..

 


I consider these restrictions to be inappropriate and unnecessary, and so I don't see why you can't do it using two data steps, or not using arrays.

 

The obvious method is to pass through the data once, obtain the maximum number of words in a given record. Then in the second data step you know how big to make the array. Now if the data set is so HUGE that passing through it twice is not a good idea, then you are stuck with solutions that will be inefficient anyway, such as setting the array size to some large number (such as 20) even when there may only be 6 names in a row, but you won't know that 6 is the number until you pass through the data, and you can't take the risk of having an array size that is too small.

--
Paige Miller
PaigeMiller
Diamond | Level 26

I should add that maybe some of the SAS Communities Hash experts can do this in a single data step; but without using hash objects I don't think it is possible.

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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