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

Hi Everyone,

------ good code----

data want; set have;
array v[*] var:;
if min(of v[*])<0 then do;
	do i=1 to dim(v);
		if v[i]<0 then do;
			output_name=row;
			output_column = vname(v[i]);
			output;
		end;
	end;
end;
run;

------

For each negative value in my table, I need to keep track of the name of row ("name") and the name of column and the value itself.

My output data should look like that 

output_row | output_column | value
loc1 | var2 | -3
loc2 | var2 | -4
loc2 | var3 | -55

 

Can anyone please help?

 

Thank you,

HHCFX

 

data have; input row $ var1 var2 var3;
datalines;
loc1 2 -3 9
loc2 4 -4 -55
loc3 4 5 6
run;

*I think it can be the approach;
data want; set have;
array v[*] var:;
do i=1 to dim(v);
	if v<0 then do;
		output_name=row;
		output_column= turn column name to text;
		output;
	end;
end;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
VNAME() function or VLABEL() for the label.

output_column = vname(v(i));


I would also recommend a quick check - check if the minimum value is less than 0. If not, you don't need to check that row at all.

View solution in original post

1 REPLY 1
Reeza
Super User
VNAME() function or VLABEL() for the label.

output_column = vname(v(i));


I would also recommend a quick check - check if the minimum value is less than 0. If not, you don't need to check that row at all.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 534 views
  • 1 like
  • 2 in conversation