DATA Step, Macro, Functions and more

dynamic variable naming

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 77
Accepted Solution

dynamic variable naming

I wish to  dynamically name a variable 'leakersN' in the code below. what is the proper code structure for dynamically naming a variable?

 

%let RN = 3725;
%put RN = &RN;

data has;
	set has;

	if FAULT_CODE = '20-2018' and VEHICLE_NO = "&RN" then
		leakers'&RN' = count(FAULT_CODE,'20-2018');
run;

Accepted Solutions
Solution
‎10-18-2017 11:01 AM
Regular Contributor
Posts: 201

Re: dynamic variable naming

Try leakers&RN = count...

View solution in original post


All Replies
Solution
‎10-18-2017 11:01 AM
Regular Contributor
Posts: 201

Re: dynamic variable naming

Try leakers&RN = count...
Frequent Contributor
Posts: 77

Re: dynamic variable naming

Posted in reply to error_prone
Thanks. A simple solution that works.
Super User
Super User
Posts: 9,386

Re: dynamic variable naming

Could you give a more concrete example?  Dataset structure should remain constant - this is how we are able to program on the data.  There is some flexibility in terms of arrays of variables, but rarely will you come across a need to have a column  dynamic like that.

 

Super User
Posts: 13,283

Re: dynamic variable naming

Kind of convoluted way to a value of 1 to a variable...

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 135 views
  • 1 like
  • 4 in conversation