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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 676 views
  • 0 likes
  • 2 in conversation