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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
ballardw
Super User

@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.
Jannie_D
Calcite | Level 5
The problem was that the daye was numeric.
also. We are creating these to avoid problems when merging dataset. . each new variable will contain the cost for that periode. If we do not do that a lot of the costs disapear when we are merging patient ID. Hens we are not creating a new variabel with a date, the variable with the date will persist. we are creating variables with cost per month.

CFC_SAS_Communities_400x225.jpgCFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2449 views
  • 0 likes
  • 3 in conversation