Hi everyone, hoping to get some help on this one.
I have a table that holds customerIDs. There are two other columns called `dateofpurchase` and 'dateofvisit'. When 'dateofpurchase' is empty, im hoping to full these cells with the same 'dateofvisit' values, kind of like a default. However, if the 'dateofpurchase' is not empty, I want to keep it as is.
I do not have code to attach since I don't know where to start.
Thanks!
I think you can do
data want (rename(dateofpurchase1=dateofpurchase) drop=dateofpurchase1 );
set have;
dateofpurchase1= ifn(' ',dateofvisit,dateofpurchase)
run;
And regarding the character value , you can change from "ifn" to "ifc" as @ballardw mentioned.
More documents for you:
Surely you could give us some sample data .... what it looks like before and what you want it to look like. Be sure to include one example where a CustomerID is missing its very first dateofpurchase.
One way would look something like this:
data want; set have; if missing(dateofpurchase) then dateofpurchase=dateofvisit; run;
The missing function tests a variable to see if it is missing and returns "true" (actually a numeric value of 1) when the variable does not have a value. If the variable is character consisting only of blanks it will also result in true.
I think you can do
data want (rename(dateofpurchase1=dateofpurchase) drop=dateofpurchase1 );
set have;
dateofpurchase1= ifn(' ',dateofvisit,dateofpurchase)
run;
And regarding the character value , you can change from "ifn" to "ifc" as @ballardw mentioned.
More documents for you:
@Phil_NZ wrote:
I think you can do
data want (rename(dateofpurchase1=dateofpurchase) drop=dateofpurchase1 ); set have; dateofpurchase1= ifn(' ',dateofvisit,dateofpurchase) run;And I think it can be applied for both numeric and character types of var.
Actually IFN works with numeric values. Character values require IFC.
@JibJam221 wrote:
thank you for this! Question - do you know if there is a way to do this for character variables as well?
The code posted by @ballardw works idependent of the variables' type. Both variables used in the assignment must have, of course, the same type.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.