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

Hi. I use SAS EG. I have two small tables. Table A: DateA,Variable A and Table B: DateB, Variable B.

I would like to end up with a Joined Table: Date_MMYYYY  Var. A Var. B.

To do this I need to (I think) convert both DateA, DateB to a real DateMMYYYY to have a common Join point.

The format change is not good enough (behind the scenes, the dates are still DDMMYYY).

Can someone help? Thanks! ( I can only think of clumsy, long ways around).

1 ACCEPTED SOLUTION

Accepted Solutions
crawfe
Quartz | Level 8

No, VDD. I meant for you to explain your logic in your code.

Next time....

I simplified the logic a little; it works for the JOIN.

DateChar = PUT(DateA,mmyys7.)   /* change to a character mm/yyyy */

BACK_toDate = INPUT(DateChar,ANYDTDTE7.) /* change back to date (num) for sorting*/

Format = mmyys7

View solution in original post

5 REPLIES 5
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
data Data1;
input ID N value1;
cards;
12 1 56
12 2 45
12 3 65
25 1 87
25 2 98
25 3 23
;

data _null_;
	date1=input(put(today(),yymmdd8.),yymmdd8.);
 	my_date = intnx('month',date1,0,'s');
	call symput('my_month',put(my_date,mmyyn6.));
put date1;
put "MY date :" my_date;
	format my_date my_month mmyyn6.;
run;
data data1&my_month.;
	set Data1;
run;
PGStats
Opal | Level 21

To clarify what you are starting with, please run the following statements:

 

proc print data=A(obs=10) noobs; format _all_; run;
proc print data=B(obs=10) noobs; format _all_; run;

and post the results with the {i} icon.

PG
crawfe
Quartz | Level 8

VDD, thanks. It would also be helpful to me and others if you could explain your logic?

 

PG Stats: They are just regular dates. DateA = 01JAN2019, DateB = 27JAN2019.

I was hoping to do a JOIN at the format level. (i.e.) 01/2019. Didn't work. Got separate lines.

01/2019     ---            Var A

----            01/2019    Var B

I am thinking I have to turn them to a Character first ('01/2019') then the JOIN

would work cleanly then convert the 'Date' back to a real Date (MM/YYYY) to be able to get

them sorted by date.

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

use the logic and replace today() with your incoming date value from each record to create a new variable that you are requesting.

If you post what you have tried and sample data rather than have us end up in left field we can assist you better.

How to create a data-step version of your data
https://communities.sas.com/t5/help/faqpage/faq-category-id/posting#posting

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

How to Add attachments
https://communities.sas.com/t5/Community-Memo/Adding-attachments-to-your-communities-posts/ba-p/4647...

 

crawfe
Quartz | Level 8

No, VDD. I meant for you to explain your logic in your code.

Next time....

I simplified the logic a little; it works for the JOIN.

DateChar = PUT(DateA,mmyys7.)   /* change to a character mm/yyyy */

BACK_toDate = INPUT(DateChar,ANYDTDTE7.) /* change back to date (num) for sorting*/

Format = mmyys7

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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