Hi. I am about to define a couple of new variables.I am working on a secure drive and can not copy paste my data or log.
I just does not work as intended. There are no errors or warnings in the log. But the data does not show up in the intended column.
So I want to create two new variables:
1: DRGambjan2014: which is the variable V_pris_genop if the date in d_hendto is jan and 2014
2:DRGambjun2014: which is the variable V_pris_genop if the date in d_hendto is jun and 2014
my code lookes like this
Data DRG1;
set DRG;
if year(d_hendto)=2014 and month(d_hendto)=jan then DRGambjan2014=v_pris_genop;
if year(d_hendto)=2014 and month(d_hendto)=jun then DRGambjun2014=v_pris_genop;
run;
it shows up as if data is missing, even where it is not.
why does it not work?
kind regards Jannie
kind regards
Show us a typical value of variable d_hendto. Is it numeric or character according to PROC CONTENTS? What format is applied to it according to PROC CONTENTS?
This line:
if year(d_hendto)=2014 and month(d_hendto)=jan then DRGambjan2014=v_pris_genop;
probably won't work because the second comparison month(d_hendto)=jan tests to see if the value of month(d_hendto) is equal to the value of the variable JAN. Does your LOG indicate variable JAN is uninitialized?
Show us a typical value of variable d_hendto. Is it numeric or character according to PROC CONTENTS? What format is applied to it according to PROC CONTENTS?
This line:
if year(d_hendto)=2014 and month(d_hendto)=jan then DRGambjan2014=v_pris_genop;
probably won't work because the second comparison month(d_hendto)=jan tests to see if the value of month(d_hendto) is equal to the value of the variable JAN. Does your LOG indicate variable JAN is uninitialized?
@Jannie_D wrote:
Hi. I am about to define a couple of new variables.I am working on a secure drive and can not copy paste my data or log.
I just does not work as intended. There are no errors or warnings in the log. But the data does not show up in the intended column.
So I want to create two new variables:
1: DRGambjan2014: which is the variable V_pris_genop if the date in d_hendto is jan and 2014
2:DRGambjun2014: which is the variable V_pris_genop if the date in d_hendto is jun and 2014
Your creation of variables with names like DRGambjun2014 means that you are placing data, year and month, into a variable name and is generally a poor idea. 90% plus of uses it is going to be better to leave a separate date variable as you currently have it. How do you expect to use the DRGambjun2014 and related variables?
my code lookes like this
Data DRG1;
set DRG;
if year(d_hendto)=2014 and month(d_hendto)=jan then DRGambjan2014=v_pris_genop;
if year(d_hendto)=2014 and month(d_hendto)=jun then DRGambjun2014=v_pris_genop;
run;
it shows up as if data is missing, even where it is not.
why does it not work?
kind regards Jannie
kind regards
The MONTH function returns a numeric value of 1 to 12. If you do not have a variable named Jan then this bit:
month(d_hendto)=jan
would likely mean that your log shows something like
NOTE: Variable jan is uninitialized.
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!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.