DATA Step, Macro, Functions and more

Problem with SAS not recognising variable during DATA step

Reply
Occasional Contributor
Posts: 9

Problem with SAS not recognising variable during DATA step

Hi There,

 

Just having a problem with SAS not recognising one of my variables whilst I am trying to encode a new variable.

 

Basically the code looks like: 

 

if CTA_LAD=1 OR CTA_CX or CTA_RCA=1 then CTAPP=1;
else CTAPP=0;

 

However, SAS seems to be creating a new variable for CTA_CX filled with missing values. As far as I can see I am typing the exact variable name as it appears in my original datasheets and the SAS output.

 

It is not doing this for any of my other recoding steps.

 

Thanks in advance for your support!

Occasional Contributor
Posts: 9

Re: Problem with SAS not recognising variable during DATA step

Addit: there was a missing space in the name that I only saw on proc print!

 

But now I am having a different problem:

 

When I try:

DATA;

rename
'CTA(space)_CX'n=CTA_CX;

RUN;

 

It replaces CTA(space)_CX with all missing values and creates a new variable CTA_CX which is also populated with missing values.

 

Thanks!

Super User
Posts: 5,260

Re: Problem with SAS not recognising variable during DATA step

Ig seems easier to start over than trying to repair something you are not really sure about.
I think that you are missing a =1 in your initial code?
Check your input data set carefully so you match variable names, data types and values.
Data never sleeps
Super User
Posts: 17,912

Re: Problem with SAS not recognising variable during DATA step

Run a proc contents to see your variable names instead of labels. I'm not sure your condition is specified correctly, I think you want what's below.

 

if CTA_LAD=1 OR CTA_CX=1 or CTA_RCA=1 then CTAPP=1;
else CTAPP=0;

 

 

Occasional Contributor
Posts: 9

Re: Problem with SAS not recognising variable during DATA step

Thanks for the reply.

 

You're correct about that bit of code being incorrect, but the renaming step is where the error is occuring in that it is creating the new variable. I copied the exact title from a PROC PRINT statement and its not working. I guess I'll just edit the original spreadsheet and try again, would have been interesting to know why this was happening. 

 

Cheers again!

Ask a Question
Discussion stats
  • 4 replies
  • 197 views
  • 0 likes
  • 3 in conversation