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

Hi all,

 

I am new here, and very newbie on SAS, so forgive me by advance for the easy question I will ask.

 

I have a table with several rows and several data such as

- a text named "TE1"

- three amounts named "AM1", "AM2", "AM3"

 

For each row, there is at least one of the three amounts not null, but for some rows two of them can be not null of even all three of them can be not null.

 

What I want to do is to create a new table with a program duplicating every row where at least two of the three amounts are not null, in order to have only one amount not null

 

Exemple of table

TE1 AM1 AM2 AM3

AZZ 12 0 1

ABB 15 0 0

AFD 12 8 5

 

I want to have in my new table

TE1 AM1 AM2 AM3

AZZ 12 0 0

AZZ 0 0 1

ABB 15 0 0

AFD 12 0 0

AFD 0 8 0

AFD 0 0 5

 

Tell me if it is not enough clear.

I have truly no ideas of how to do it. Can you help me?

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Loko
Barite | Level 11

Hello,

 

data want;
set have;

array no{*} AM1 AM2 AM3;
array no_new{*} AM1_ AM2_ AM3_;

do i=1 to dim(no);
 if no{i} ne 0 then 
	do;
	  do j=1 to dim(no);
	  	if j=i then no_new{j}=no{i};
		else  no_new{j}=0;
	  end;
      output;
	end;
end;

drop AM1-Am3 i j;

rename 
am1_=am1
am2_=am2
am3_=am3;
run;

View solution in original post

2 REPLIES 2
Loko
Barite | Level 11

Hello,

 

data want;
set have;

array no{*} AM1 AM2 AM3;
array no_new{*} AM1_ AM2_ AM3_;

do i=1 to dim(no);
 if no{i} ne 0 then 
	do;
	  do j=1 to dim(no);
	  	if j=i then no_new{j}=no{i};
		else  no_new{j}=0;
	  end;
      output;
	end;
end;

drop AM1-Am3 i j;

rename 
am1_=am1
am2_=am2
am3_=am3;
run;
Planck
Obsidian | Level 7

Exactly what I needeed!

 

Thank you very much for the fast answer, and the efficiancy!

Happy new year 2017!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 908 views
  • 0 likes
  • 2 in conversation