BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ebowen
Quartz | Level 8

I have a dataset sorted by three variables, and I'm trying to copy another variable from the previous observation within each grouping conditional on whether the variable has a value or not. So far, here's the code that I have:

DATA test3;

length V1 8;

Set FuelCost11;

By PlantID PMStd Fuel;

Retain V1;

if first.Fuel then V1 = .;

if HeatRate ^=. then V1 = HeatRate;

HeatRate = V1;

Run;

When I run this code, I get the following error:

"ERROR: Variable V1 has been defined as both character and numeric."

I don't know why this would happen, since I'm defining the variable V1 as a numerical variable in the first statement of the data step. The variable V1 doesn't exist prior to this data step. I've run this same code with a character variable (after defining V1 as $5), and it works perfectly. Thanks in advance for any help you can provide.

1 ACCEPTED SOLUTION

Accepted Solutions
ebowen
Quartz | Level 8

It turns out I had defined V1 previously as a character variable. After fixing that, the code works great. Sorry for the mix-up.

View solution in original post

4 REPLIES 4
Reeza
Super User

What variable type is HeatRate? Your missing a period after the eight in the length statement, not sure if thats an issue as well.

Can you post proc contents results on FuelCost11?

ebowen
Quartz | Level 8

It turns out I had defined V1 previously as a character variable. After fixing that, the code works great. Sorry for the mix-up.

data_null__
Jade | Level 19

Why would you need a period after 8 in the length statement.

Reeza
Super User

I realized that and deleted it...but the forums are having issues today...or maybe I am.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 848 views
  • 3 likes
  • 3 in conversation