DATA Step, Macro, Functions and more

Separate numbers with slash

Reply
Occasional Contributor
Posts: 14

Separate numbers with slash

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. 

 
PROC Star
Posts: 2,375

Re: Separate numbers with slash

[ Edited ]
Posted in reply to SuperSaiyan

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.

 

Occasional Contributor
Posts: 14

Re: Separate numbers with slash

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?
Super User
Posts: 10,287

Re: Separate numbers with slash

Posted in reply to SuperSaiyan

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
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 6

Re: Separate numbers with slash

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

Contributor
Posts: 56

Re: Separate numbers with slash

Posted in reply to neha_gupta

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;

 

Super User
Super User
Posts: 8,130

Re: Separate numbers with slash

Posted in reply to SuperSaiyan

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

 

PROC Star
Posts: 2,375

Re: Separate numbers with slash

Posted in reply to SuperSaiyan
Putlog writes in the log.

Use the same format on proc print.
Ask a Question
Discussion stats
  • 7 replies
  • 251 views
  • 0 likes
  • 6 in conversation