Hello,
If anyone can help me with my code. I need to place an existing value to a new variable, instead it's giving me a zero value.
Code:
DATA ALLC; SET ALLB;
LENGTH NPN $5;
IF (C_ID=C_IDN) AND (TDTN > PDT) THEN NPN=FIRST.PN;
ELSE NPN = PN;
RUN;
PROC PRINT N; ID C_ID; VAR CPRENDINGDT PDT TDTN NPN PN;
RUN;
My Result: Pelase see attachement.
Thank you.
You can't use first.pn without including a
by pn;
statement
Art, CEO, AnalystFinder.com
First.PN will always be 1 or 0, as it's an indicator if a record is the first record or not. It does not hold the value of the first value of PN which is what I think you're looking for, see the code below. I had to add, BY and RETAIN statements and modified the code to keep the first variable.
Please clarify your question by describing what you want rather than code that doesn't work.
Also, post sample data as text directly in the forum as mnay users won't work with xlsx or docx files.
DATA ALLC; SET ALLB;
LENGTH NPN $5;
by PN;
Retain First_PN;
if first.PN then First_PN= PN;
IF (C_ID=C_IDN) AND (TDTN > PDT) THEN NPN=First_PN;
ELSE NPN = PN;
RUN;
Are pdt and tdtn sas dates or just character fields containing date looking information? If they're character fields, in addition to the first. problem, your logic won't work as expected.
Art, CEO, AnalystFinder.com
Hello,
I didn't make my question clear, please see the attachement for more details. Thank you.
I need to compare the C_ID with C_IDN and if the CEDT and PDT the same than create a new varaible named NPN with the PN's value and if the PDT is less than the TDTN than I want the previous PN value for the NPN vaule.
You didn't answer my question: are the dates character fields or SAS dates?
Art, CEO, AnalystFinder.com
OK. But your question still isn't clear. You said:
I need to compare the C_ID with C_IDN and if the CEDT and PDT the same than create a new varaible named NPN with the PN's value and if the PDT is less than the TDTN than I want the previous PN value for the NPN vaule.
You mention comparing C_ID with C_IDN, but didn't say anything about what if they are equal or unequal. Are you saying that if C_ID and C_IDN are the same, and if CEDT and PDT are the same, then create the new variable equal to the PN value.
Do you want to do the pdt less than computation ONLY if the condition in the last paragraph isn't met?
Art, CEO, AnalystFinder.com
Did you try the code? What part of it was incorrect?
When you say previous value, are you referring to the previous value as the previous row, or the previous value as the previous value in the series.
Small sample datasets that show input and output goes a long way..
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.
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.