BookmarkSubscribeRSS Feed
SuperSaiyan
Calcite | Level 5

Hello

I want to separate the numbers with slashes

the data i have is something like this 100287 211178

 

I tried the suggested solution on other threads, see below:

 

data want;
input datevar ddmmyy6.;
format datevar ddmmyys8.;
cards;160911
151111;
run;

 however SAS converts it to a SAS date(?) so, 100287 becomes 300734 then formatting it with slashes it becomes 30/07/34, this is incorrect, I want to retain the values but separted only with slashes. 

 
7 REPLIES 7
ChrisNZ
Tourmaline | Level 20

This works fine for me:

data HAVE;
  input DATEVAR ddmmyy6.; 
  putlog DATEVAR= date9. DATEVAR= ddmmyys8.;
cards;
160911
151111
run;

DATEVAR=16SEP2011 DATEVAR=16/09/11
DATEVAR=15NOV2011 DATEVAR=15/11/11

 

Your code runs fine too, so you are doing something else.

 

SuperSaiyan
Calcite | Level 5
hello thank you, it worked as expected, but is there any alternative for putlog? It was not taught in my class. is there a way to format it in proc print?
Kurt_Bremser
Super User

@SuperSaiyan wrote:
hello thank you, it worked as expected, but is there any alternative for putlog? It was not taught in my class. is there a way to format it in proc print?

Proc print will work with your code out-of-the-box, just test it:

data want;
input datevar ddmmyy6.;
format datevar ddmmyys8.;
cards;
160911
151111
;
run;

proc print data=want noobs;
run;

The only thing I had to correct was the formatting of the cards; block.

Result:

 datevar

16/09/11
15/11/11
neha_gupta
Calcite | Level 5

Hi Rich Sorry I am new in SAS.Could you please explain me what is the use of putlog? Thanks in advance 

rvsidhu035
Quartz | Level 8

put function shows log file at pdv

from source - pdv-ouput

you check

 

data ravi;

set sashelp.class;

if age=11 then status="chiled";

put  _all_;


run;

 

Tom
Super User Tom
Super User

The code you posted isn't going to run since you didn't put the data on separate lines from the CARDS: statement or the semi-colon that ends it.  If we fix that 

data want;
input datevar ddmmyy6.;
format datevar ddmmyys8.;
cards;
160911
151111
;
proc print;
run;

then it looks like it works.

Obs     datevar

 1     16/09/11
 2     15/11/11

 

ChrisNZ
Tourmaline | Level 20
Putlog writes in the log.

Use the same format on proc print.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 2046 views
  • 0 likes
  • 6 in conversation