BookmarkSubscribeRSS Feed
sas_university
Obsidian | Level 7

data ds;

infile datalines;

input id  team$ loc$;

datalines;

10 red  nlr

11 green tpt

12 tellow klr

;

run;

data ds1;

set ds;

if  team='red' then members=' ravi, sekhar,pawan';

run; 

 

output  required ;

ravi

sekhar 

pawan

i want vertical data expected output anyone can help me 

output :

ravi, sekhar,pawan 

 

anyone can help me 

 

 

 

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

By 'vertical', do you mean that you want 1 obs per name if team = 'Red'?

sas_university
Obsidian | Level 7

Hi sir..

 

example :

if team=red then name=ravi, venu ,sai

 

when i am convert excel file in column output be like :

name

ravi

venu

sai

 

help me

 

 

Kurt_Bremser
Super User
data want;
set have (rename=(name=_name));
do i = 1 to countw(_name,",");
  name = scan(_name,i,",");
  output;
end;
drop i _name;
run;

Untested for lack of usable example data.

ballardw
Super User

Output where? An external text file? An ODS destination? The Log? A data set with each value a separate observation?

 

This will print one word for each value of Members to the default output destination window.

data ds;
infile datalines;
file print;
input id  team$ loc$;
if  team='red' then members=' ravi, sekhar,pawan';
do i=1 to countw(members);
   word = scan(members,i);
   put word;
end;
datalines;
10 red  nlr
11 green tpt
12 tellow klr
;
Vivi1997
SAS Employee
data ds (drop=members i);
infile datalines;
file print;
input id  team$ loc$;
members=' ravi, sekhar,pawan';
do i=1 to countw(members);
   if team = 'red' then member = scan(members,i);
   output;
end;
datalines;
10 red  nlr
11 green tpt
12 tellow klr
;

You can simply run a do loop for all the members and check for team red then output the appropriate member at the end of each iteration. However this will create 3 rows for each team since 3 members are specified at the beginning. Hope this helps!

Output:

Vivi1997_0-1664261995385.png

 

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
  • 5 replies
  • 1396 views
  • 0 likes
  • 5 in conversation