BookmarkSubscribeRSS Feed
RAVI2000
Lapis Lazuli | Level 10

Hello Everyone,

I have a variable cars which has 4 different values. Some records have multiple values in it(the dataset looks like one row by showroom). I want to create a dataset with multiple records where I want to search for the a particular string value and give it one row each(dataset looks like it has multiple records by showroom). 

RAVI2000_1-1643931564517.png

I tried using Index, but didn't give the desired result.

 

Thanks

 

8 REPLIES 8
Reeza
Super User
Can you show what you tried with index?
RAVI2000
Lapis Lazuli | Level 10
How do I divide the values for one showroom and put them into rows?
The Index really does't really helped.
RAVI2000
Lapis Lazuli | Level 10
data PD3;
	set PD2;
	
	if cars ne "" and index(compress(lowcase(cars)),"audionroad") then flag1 = "Audi on road";
	if cars ne "" and index(compress(lowcase(cars)),"benzonroad")then flag2 = "Benz on road";
	if cars ne "" and index(compress(lowcase(cars)),"hondaonroad") then flag3 = "Honda on road";
	if cars ne "" and index(compress(lowcase(cars)),"fordonroad") then flag4 = "Ford on road";
	if cars ne "" and index(compress(lowcase(cars)),"porche") then flag5 = "Porche";
	
run;

data PD4;
	group = 'A';
	do until(done1);
		set PD3(rename=(flag1=flag)) end=done1;
		output;
	end;
	
	group = 'B';
	do until(done2);
		set PD3(rename=(flag2 = flag)) end=done2;
		output;
	end;
run;

It is not giving what I want.

andreas_lds
Jade | Level 19

If the screenshot shows what you want, then you need only one flag variable and use the output statement in each if.

if cars ne "" and index(compress(lowcase(cars)),"audionroad") then do;
  flag = "Audi on road";
  output;
end;
andreas_lds
Jade | Level 19

Have you read the links posted by @Reeza ? The first one suggest a solution, so have a look at the documentation of the function countw and scan and the output statement, all combined with a loop solves your problem.

andreas_lds
Jade | Level 19

Have you read the links posted by @Reeza ? The first one suggest a solution, so have a look at the documentation of the function countw and scan and the output statement. Used within a loop, your task can be solved in a single step.

s_lassen
Meteorite | Level 14

Looks like your multiple cars are nicely separated by commas. So this may work:

data want;
  set have;
  do _N_=1 by 1;
    car=scan(cars,_N_,',');
    if car=' ' then leave;
    output;
    end;
  drop cars;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 8 replies
  • 651 views
  • 1 like
  • 4 in conversation