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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 609 views
  • 0 likes
  • 3 in conversation