BookmarkSubscribeRSS Feed
lsw2920
Calcite | Level 5

I'm new to SAS and trying to program a simple code.


Original data:
TableA

ID   |    Date      | Type

1      20111111       A

2      20081014     C

3      20051126      A

...

100  20160421      B

 

From this original data, I want to pick up dates by Type.

Like following

 

Result (only picking up A & B)

ID   | DateofA     | DateofB

1     | 20111111  |

2     |                  |

3     | 20051126 |

...

100 |                  | 20160421

 

 

Are there anyone know how to program this?

 

Thank you for advance.

 

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Thats called transposing data:

proc sort data=have;
  by id type;
run;
proc transpose data=have out=want prefix=dateof;
  var date;
  id type;
  idlabel type;
run;
ballardw
Super User

If the function Year(date) for your example value of 20111111 does not return 2011 then you don't actually have "dates" you only have numeric (or possibly character) values and you might want consider creating actual date values so that you can manipulate them with the proper SAS functions and formats.

 

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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