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

how can i get the date while i using named input format??

data d;

input id= name=$20. dob=ddmmyy10. sal= desig=$20.;

format dob ddmmyy10.;

cards;

desig=Assistant manager id=100 name=krishna chandran sal=5000 dob=21/09/1989

id=101 dob=10/05/2010 desig=engineer sal=8000 name=hareesh Menon

run;

while i run this code i couldn't view the date in table.Any one can suggest some tips for fixing the problem as soon as possible

1 ACCEPTED SOLUTION

Accepted Solutions
LakshmiK
Calcite | Level 5

Hope this would help you.

I could do it in two steps...

data d;

input id= name=$20. dob=$10. sal= desig=$20.;

cards;

desig=Assistant manager id=100 name=krishna chandran sal=5000 dob=21/09/1989

id=101 dob=10/05/2010 desig=engineer sal=8000 name=hareesh Menon

quit;

data r;

  set d;

  dob_ = input(dob,ddmmyy10.);

  format dob_ ddmmyy10.;

  drop dob;

  rename dob_ = dob;

run;

Try this..

Lakshmi.

View solution in original post

10 REPLIES 10
LakshmiK
Calcite | Level 5

Hope this would help you.

I could do it in two steps...

data d;

input id= name=$20. dob=$10. sal= desig=$20.;

cards;

desig=Assistant manager id=100 name=krishna chandran sal=5000 dob=21/09/1989

id=101 dob=10/05/2010 desig=engineer sal=8000 name=hareesh Menon

quit;

data r;

  set d;

  dob_ = input(dob,ddmmyy10.);

  format dob_ ddmmyy10.;

  drop dob;

  rename dob_ = dob;

run;

Try this..

Lakshmi.

KrishnaChandra
Calcite | Level 5

Hai Lekshmi i got the output with your code..Thanks for your valuable reply

Krishna

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Well, I have never seen that type of cards statement use before.  Unusual.  Personally I would agree with Chrishi, one step approach.  Firstly define what you want your output dataset to look like - the attrib statements - then have an infile statement to define delimiter (because if you have more than 10 rows of data you don't want to be typing variable names each time - unless you like typing?).  Then input the data.  This approach would also work entering data into Excel for instance and then importing, just change the infile from cards to a filename.

KrishnaChandra
Calcite | Level 5

Thanks RW9 for your valuable information.Am beginner in SAS Technology.I need to learn more from sas

Reagrds

Krishna

RW9
Diamond | Level 26 RW9
Diamond | Level 26

No probs.  I forgot to actually include the code on my post:

data d;

  attrib  id format=$20.

          name format=$20.

          dob format=ddmmyy10. informat=ddmmyy10.

          sal format=best.

          desig format=$20.;

  infile cards delimiter=',';

  input id name $ dob sal desig $;

cards;

100,krishna chandran,21/09/1989,5000,assistant manager

101,hareesh menon,10/05/2010,8000,engineer

run;

Chrishi
Calcite | Level 5

Hi

you have to give informat before the input line for dob that will resolve your problem i hope.

data d;

informat dob ddmmyy10.;

input id= name=$20. dob= sal= desig=$20.;

format dob ddmmyy10.;

cards;

desig=Assistant manager id=100 name=krishna chandran sal=5000 dob=21/09/1989

id=101 dob=10/05/2010 desig=engineer sal=8000 name=hareesh Menon

run;

Thanks,

Sudeer.

KrishnaChandra
Calcite | Level 5

Thanks Sudeer.

while i using with your code.The table shown the 3rd observations as filled with period(.)

I also need to get the columns in proper order..How could it possible Sudeer?

Regards

Krishna

data_null__
Jade | Level 19

Named input can be useful.  I would write it like this to define the variables, provide INFORMATS and FORMATS as needed, and get them in the order you desire.  Plus it makes you look like you know what you're doing. Smiley Happy

data namedinput;
   attrib id    length=8;
  
attrib name  length=$20;
  
attrib dob   length=8 informat=ddmmyy10. format=ddmmyyd10.;
  
attrib sal   length=8;
  
attrib desig length=$20;
  
infile cards;
  
input (_all_)(=); 
  
cards;
desig=Assistant manager id=100 name=krishna chandran sal=5000 dob=21/09/1989
id=101 dob=10/05/2010 desig=engineer sal=8000 name=hareesh Menon
run;

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
  • 10 replies
  • 1285 views
  • 9 likes
  • 5 in conversation