Data visualization with SAS programming

Problems with Variable Names in Caterpillar Macro

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Problems with Variable Names in Caterpillar Macro

[ Edited ]

Hi everyone,

 

I am trying to show certain parameter estimates in a caterpillar graph.

I am conducting a Bayesian analysis with proc bchoice and get many different estimates per individual (I have 1,000 survey participants).

So e.g. I have a variable that is named AA,N 0001 which is the estimate for AA for individual 0001.

I am trying to put all estimates in a caterpillar graph but it wouldn't work.

 

I have tired %cater(datat=mydata, var=AA,N_: ) ; but I get: All positional parameters must percede keyword parameters.

If I try %cater(datat=mydata, var=AA: ) ; but I get: Syntax error.

 

Thanks for your help!

 

Best,
Alex


Accepted Solutions
Solution
‎09-01-2016 04:21 AM
SAS Super FREQ
Posts: 8,717

Re: Problems with Variable Names in Caterpillar Macro

Hi:
How are these variable names being created? By what procedure?

Just curious what will happen if you issue:
options validvarname=v7;

and see whether your variable names get changed to something like AA_N_001 and AA_N_002, etc. Or whether you get error messages.

It would be very unusual for a SAS procedure to make a variable name with a comma and a blank in the name. You might want to open a ticket with Tech Support.

Under normal circumstances, I would expect some kind of error like this:
ERROR: The value AA,N 001 is not a valid SAS name.

but it would have to happen in the step some place before your macro call.

The bottom line is that you can't have a comma in the variable name and I'm not sure that quoting functions or using a named literal will help you here because I am not sure using a named literal like 'AA,N 001'n will work in the Macro program. That would be a question for Tech Support.

cynthia

View solution in original post


All Replies
SAS Super FREQ
Posts: 8,717

Re: Problems with Variable Names in Caterpillar Macro

Hi:
Did you test out the example in the DOC? When I tried the example shown here:
http://support.sas.com/documentation/cdl/en/statug/65328/HTML/default/viewer.htm#statug_mcmc_details...
for the %CATER macro all the statements ran for me without any macro errors such as you report.

In the documentation example, the PROC MCMC step creates DELTA_1 thru DELTA_21 variables, so the macro parameter in the doc shows:
%CATER(data=postout, var=deltaSmiley Happy, which to me indicates that the macro program was designed to take one value, not values separated with commas. But a variable name of "AA,N 001" is not a valid variable name. SAS variable names cannot contain commas or spaces.

Have you run a PROC CONTENTS on your data to see what the variable names are -- it seems like you might be using labels instead of variable names.

cynthia
Contributor
Posts: 20

Re: Problems with Variable Names in Caterpillar Macro

Hi Cynthia,

 

thank your for your quick answer. I just ran proc contents and it shows me the variable names (e.g. AA,N 0001, AA,N 0002, etc.), the type (numerical) and the length (8).

Do you think I have to rename the variables?

 

Thank you!

Alex

Solution
‎09-01-2016 04:21 AM
SAS Super FREQ
Posts: 8,717

Re: Problems with Variable Names in Caterpillar Macro

Hi:
How are these variable names being created? By what procedure?

Just curious what will happen if you issue:
options validvarname=v7;

and see whether your variable names get changed to something like AA_N_001 and AA_N_002, etc. Or whether you get error messages.

It would be very unusual for a SAS procedure to make a variable name with a comma and a blank in the name. You might want to open a ticket with Tech Support.

Under normal circumstances, I would expect some kind of error like this:
ERROR: The value AA,N 001 is not a valid SAS name.

but it would have to happen in the step some place before your macro call.

The bottom line is that you can't have a comma in the variable name and I'm not sure that quoting functions or using a named literal will help you here because I am not sure using a named literal like 'AA,N 001'n will work in the Macro program. That would be a question for Tech Support.

cynthia
Contributor
Posts: 20

Re: Problems with Variable Names in Caterpillar Macro

Hi Cynthia,

 

the variables are produced by the BCHOICE procedure. I am using the "random" option in order to create a random effects model.

The variables are produced in the output data set.

 

Best,

Alex

SAS Super FREQ
Posts: 3,406

Re: Problems with Variable Names in Caterpillar Macro

I think you are seeing labels, not variable names. Run the following to see the real names:

 

proc contents data=MY_OUTPUT_DATA short;

run;

 

You ought to be able to cut and paste from that output into the macro.

 

I ran the Getting Started example, which uses a RANDOM statement. I used the OUTPOST= option on the PROC BCHOICE statement to create an output data set.  In that example, the variable names are created as normal SAS variables, but the labels are as you described.

Contributor
Posts: 20

Re: Problems with Variable Names in Caterpillar Macro

Hi,

 

I did run proc contents and it shows me the Variables (AA,N 0001), its type, the length and the label (AA,N 0001). So the label and the variable name seem to be identical in this case. How can this be?

SAS Super FREQ
Posts: 3,406

Re: Problems with Variable Names in Caterpillar Macro

Please provide

1. the PROC BCHOICE code that you are using

2. The output from

    proc contents data=MY_OUTPUT_DATA    SHORT;

    run;

    where you replace MY_OUTPUT_DATA by the name of the data set created by PROC BCHOICE.

Contributor
Posts: 20

Re: Problems with Variable Names in Caterpillar Macro

proc bchoice    data=CSDesignEffect outpost=EffectPost
                nmc=5000 thin=2 seed=123
                nthreads=4 ;
class N Set;

model choice=     No
                AA AF BA DL _50_ _100_
                P1100 P1300 P1800 P2000
                /    choiceset=(Set);

                random AA _50_  P1100
                / subject=N
                monitor=(1 to 5) type=un;
run;

Attachment
SAS Super FREQ
Posts: 3,406

Re: Problems with Variable Names in Caterpillar Macro

You dd not use the SHORT option:

 

proc contents data=EffectPost  SHORT;

run;

SAS Super FREQ
Posts: 3,406

Re: Problems with Variable Names in Caterpillar Macro

Please also submit

 

proc options option=validvarname value;
run;

 

and copy/paste the output that appears in the SAS log.  It will look something like this:

 

Option Value Information For SAS Option VALIDVARNAME
Value: V7
Scope: Default
How option value set: Shipped Default

Contributor
Posts: 20

Re: Problems with Variable Names in Caterpillar Macro

Hi,

 

the validvarname=v7 code worked, thank you very much Rick and Cynthia!

 

Best,
Alex

☑ This topic is SOLVED.

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

Discussion stats
  • 11 replies
  • 395 views
  • 0 likes
  • 3 in conversation