DATA Step, Macro, Functions and more

Labeling Variables based on other variable names

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Labeling Variables based on other variable names

Hello!

 

I'm working on creating a label for variables that are being created, but I'd like them to have the old names as their labels.  I keep gettin an error message saying there is a syntax error on the LABEL line.

 

Any help is greatly appreciated!!

 

DATA %SCAN(&DATA,&i);
SET %SCAN(&DATA,&i);
ARRAY %SCAN(&DATA,&i) [&Count] &List;
ARRAY BIN_%SCAN(&DATA,&i)[&Count] BIN_%SCAN(&DATA,&i)1 - BIN_%SCAN(&DATA,&i)&Count;
DO j = 1 TO &Count;
IF %SCAN(&DATA,&i)(j) = '' THEN BIN_%SCAN(&DATA,&i)(j) = 0;
ELSE BIN_%SCAN(&DATA,&i)(j) = 1;
LABEL BIN_%SCAN(&DATA,&i)(j) = %SCAN(&DATA,&i)(j);
END;
FORMAT BIN_%SCAN(&DATA,&i)1 - BIN_%SCAN(&DATA,&i)&Count Issues.;
RUN;


Accepted Solutions
Solution
‎01-30-2016 03:52 PM
Contributor
Posts: 30

Re: Labeling Variables based on other variable names

Thank you!  I looked at it differently and did make it much easier.  

 

Thank you Smiley Happy.

View solution in original post


All Replies
Super User
Posts: 19,791

Re: Labeling Variables based on other variable names

I don't think you can reference a variable to assign a label by using the array reference, ie this line:

 

LABEL BIN_%SCAN(&DATA,&i)(j) = %SCAN(&DATA,&i)(j);

You'll need to either get the variables names which you may have in another macro variable (LIST)

or you can do it in another step, using the metadata from SASHELP.VCOLUMN and PROC DATASETS.

 

I'm looking at your code though and betting there's an easier way to accomplish what you're trying to do....so what are you trying to do Smiley Happy

Solution
‎01-30-2016 03:52 PM
Contributor
Posts: 30

Re: Labeling Variables based on other variable names

Thank you!  I looked at it differently and did make it much easier.  

 

Thank you Smiley Happy.

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 201 views
  • 1 like
  • 2 in conversation