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

Hello SAS.

 

I need some help with following situation :

I have two tables :

NOCONT

prod

DPD_0

DPD0

CDSITC1

DAT_REST

STARE1

TOTAL11

DPD_1

DPD WCS

DPD1

Scadenta

500338833

CR

0

B0. 0

1

20181015

A

2925.076

9

39

B1. 1-30

22

and

NOCONT

DTCSTS03

5416257158

20180718

500338833

20180731

 I want to add DTCSTS03 from second table to equivalent NOCONT in first table , also I need a modify the structure and format of DTCSTS03

I want to modify from 20180731 to 07/31/2018 and to replace de 31 with value of scadenta column.

in excel I use vlookup and DATE(LEFT(A2,4),RIGHT(LEFT(A2,6),2),RIGHT(A2,2)) date formula to make those changes , In SAS I didn't manage to create something near close.

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Then do this:

data want;
merge
  table_1 (in=a)
  table_2 (
    in=b
    rename=(dtcsts03=_dtcsts03)
  )
;
by nocont;
format dtcsts03 mmddyy10.;
if a;
if b then dtcsts03 = input(substr(put(_dtcsts03,8.),1,6) !! put(scadenta,z2.),yymmdd8.);
drop _dtcsts03;
run;

The tables have to be sorted by nocont, and scadenta is assumed to be a number; if it's character, omit the put() function around it.

Your new dtcsts03 will be a real, usable SAS date value.

View solution in original post

4 REPLIES 4
Unstefan
Calcite | Level 5

DTCSTS03 is number format best12. informat best12.

Kurt_Bremser
Super User

Then do this:

data want;
merge
  table_1 (in=a)
  table_2 (
    in=b
    rename=(dtcsts03=_dtcsts03)
  )
;
by nocont;
format dtcsts03 mmddyy10.;
if a;
if b then dtcsts03 = input(substr(put(_dtcsts03,8.),1,6) !! put(scadenta,z2.),yymmdd8.);
drop _dtcsts03;
run;

The tables have to be sorted by nocont, and scadenta is assumed to be a number; if it's character, omit the put() function around it.

Your new dtcsts03 will be a real, usable SAS date value.

Unstefan
Calcite | Level 5

thank you for your time

you are the best , I will add some things to database

if I will have problems I will contact you

thank you again

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1576 views
  • 0 likes
  • 2 in conversation