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

Hi to everyone, in order to understand the way to mix different kind of charater data, numerical data, and informat data as date,

this input is reading correctly,

but I would like someone can explain me the role of the colon and ampersand in this code,

necessary to make it works.

Thanks,

V.

data new3;

format dat date9. date mmddyy10.;

input obs subjid pp ae: & $14. dat: date9. trt: $10. date: mmddyy10. treatment $10.;

datalines;

  1       1000000134     0  headache       23jan63       placebo   10/10/2005  drug

  1       1000000234     0  lung left pain       23jan34       placebo   10/10/1995  drug

  1       1000000134     0  headache       23jan63       placebo   10/10/2005  drug

;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The & lets you read character strings with embedded single blanks.  In your example the AE variable.

The : tells SAS not to take the informat literally.  Instead of reading 14 characters for the treatment code 'placebo' it will stop when it sees the space. This will prevent it from "eating" (a very techinical term) the beginning of the date variable.

I usually find that it is better to use a LENGTH statement or ATTRIB statements to define the variables BEFORE the input statement.  This also has the advantage of allowing you to set the order that the variables will appear in your dataset.  Currently DAT and DATE will appear first because they are mentioned first (in the FORMAT statement).

You can also assign INFORMATs for the variables that need them (such as date and time values).

Then the input statement is much easier.  For your data the only thing that you would need special in your INPUT statement would be the & because of the embedded delimiters in the value of AE variable.  You might want to used a delimiter other than space.

data new4;

length obs subjid pp 8 ae $14 dat 8 trt $10 date 8 treatment $10;

informat dat date9. date mmddyy10.;

format dat date yymmdd10.;

input obs subjid pp ae & dat trt date treatment;

datalines;

  1       1000000134     0  headache       23jan63       placebo   10/10/2005  drug

  1       1000000234     0  lung left pain       23jan34       placebo   10/10/1995  drug

  1       1000000134     0  headache       23jan63       placebo   10/10/2005  drug

;

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

The & lets you read character strings with embedded single blanks.  In your example the AE variable.

The : tells SAS not to take the informat literally.  Instead of reading 14 characters for the treatment code 'placebo' it will stop when it sees the space. This will prevent it from "eating" (a very techinical term) the beginning of the date variable.

I usually find that it is better to use a LENGTH statement or ATTRIB statements to define the variables BEFORE the input statement.  This also has the advantage of allowing you to set the order that the variables will appear in your dataset.  Currently DAT and DATE will appear first because they are mentioned first (in the FORMAT statement).

You can also assign INFORMATs for the variables that need them (such as date and time values).

Then the input statement is much easier.  For your data the only thing that you would need special in your INPUT statement would be the & because of the embedded delimiters in the value of AE variable.  You might want to used a delimiter other than space.

data new4;

length obs subjid pp 8 ae $14 dat 8 trt $10 date 8 treatment $10;

informat dat date9. date mmddyy10.;

format dat date yymmdd10.;

input obs subjid pp ae & dat trt date treatment;

datalines;

  1       1000000134     0  headache       23jan63       placebo   10/10/2005  drug

  1       1000000234     0  lung left pain       23jan34       placebo   10/10/1995  drug

  1       1000000134     0  headache       23jan63       placebo   10/10/2005  drug

;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 685 views
  • 0 likes
  • 2 in conversation