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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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