Using concatenation with IDLABEL

Reply
Occasional Contributor
Posts: 8

Using concatenation with IDLABEL

[ Edited ]

It would be helpful to have concatenation on the IDLABEL statement. At the moment it only allows variables like:

IDLABEL alergy_variable; * where 'alergy_variable' may be 'Milk', 'Beef', or whatever the value of the variable is; 

 

However the IDLABEL statement is for 'labeling' so it would be nice if the statement would allow for better dynamic labeling like so:

IDLABEL cat("Do you think you have a food alergy to...",alergy_variable);
Super User
Posts: 13,563

Re: Using concatenation with IDLABEL

Simple, create the variable with the label you want before proc transpose.

Occasional Contributor
Posts: 8

Re: Using concatenation with IDLABEL

Thanks but I wanted to avoid manually entering a long list of variable names before I run PROC TRANSPOSE.  It would save some time to simply be able to do the concatenation within PROC TRANSPOSE.

Super User
Posts: 13,563

Re: Using concatenation with IDLABEL


@wpg_unc wrote:

Thanks but I wanted to avoid manually entering a long list of variable names before I run PROC TRANSPOSE.  It would save some time to simply be able to do the concatenation within PROC TRANSPOSE.


Possibly this comment is because you are unfamiliar with some of the less known functions such as VNAME and the use of arrays.

This creates a not terribly fancy variable to hold text build in the fashion you describe.

 

data example;
   set sashelp.class (obs=1);
   array n _numeric_;
   array c _character_;
   length Idvar $ 100;
   do i=1 to dim(n);
      idvar = catx(" ","This is the label for variable",vname(n[i]));
      output;
   end;
   do i=1 to dim(c);
      idvar = catx(" ","This is the label for variable",vname(c[i]));
      output;
   end;
   keep idvar;
run;

But since you have posted 1) no starting data, 2) no actual desired result and 3) have not even bothered to name the procedure this is supposed to modify (it's lucky you weren't trying to do something to ID has many procedures have ID statements) it is hard to provide a more targeted response.

 

 

Since IDLABEL is designed to point to a VARIABLE not an explicit text value this would be a very extreme departure from the existing behavior. Perhaps if you declared appropriate LABELS when the data were originally created a double transpose might help here. But no example data ....

Super User
Posts: 23,754

Re: Using concatenation with IDLABEL

Suggestions for improvements or modifications can be made in SAS Ballotware section here:

https://communities.sas.com/t5/SASware-Ballot-Ideas/idb-p/sas_ideas

 

 

As indicated however, this is relatively easy to work around, you can add a previous step that creates the variable as desired in the data set. Another option, if you want it in one step is to use VALIDVARNAME=ANY, then you can have the actual variable labelled as 'My long text label' and list them in ID statement as well. There's the DELIM option to add a separator for the ID variables. 

 


@wpg_unc wrote:

It would be helpful to have concatenation on the IDLABEL statement. At the moment it only allows variables like:

IDLABEL alergy_variable; * where 'alergy_variable' may be 'Milk', 'Beef', or whatever the value of the variable is; 

 

However the IDLABEL statement is for 'labeling' so it would be nice if the statement would allow for better dynamic labeling like so:

IDLABEL cat("Do you think you have a food alergy to...",alergy_variable);

 

 

Occasional Contributor
Posts: 8

Re: Using concatenation with IDLABEL

I submitted this question as a feature request.

Ask a Question
Discussion stats
  • 5 replies
  • 124 views
  • 2 likes
  • 3 in conversation