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

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 346 views
  • 1 like
  • 2 in conversation