DATA Step, Macro, Functions and more

Input statement: How do I read multiple words as one string variable.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Input statement: How do I read multiple words as one string variable.

[ Edited ]

Hello everyone,

 

I am looking to read ICD10 diagnosis codes into one variable and the code description in another variable.

 

What is the input statement switch that will allow me to do this?

 

Example: Newborn only diagnosis codes and descriptions:

 

 

DATA sparcs.input_newborn_icd10_2017;

INPUT DX $ ;

DATALINES;

A33 Tetanus neonatorum

E8411 Meconium ileus in cystic fibrosis

H04531 Neonatal obstruction of right nasolacrimal duct

H04532 Neonatal obstruction of left nasolacrimal duct

H04533 Neonatal obstruction of bilateral nasolacrimal duct

H04539 Neonatal obstruction of unspecified nasolacrimal duct

N470 Adherent prepuce, newborn

Z00110 Health examination for newborn under 8 days old

Z00111 Health examination for newborn 8 to 28 days old

Z3800 Single liveborn infant, delivered vaginally

Z3801 Single liveborn infant, delivered by cesarean

Z381 Single liveborn infant, born outside hospital

Z382 Single liveborn infant, unspecified as to place of birth

Z3830 Twin liveborn infant, delivered vaginally

Z3831 Twin liveborn infant, delivered by cesarean

Z384 Twin liveborn infant, born outside hospital

Z385 Twin liveborn infant, unspecified as to place of birth

Z3861 Triplet liveborn infant, delivered vaginally

Z3862 Triplet liveborn infant, delivered by cesarean

Z3863 Quadruplet liveborn infant, delivered vaginally

Z3864 Quadruplet liveborn infant, delivered by cesarean

Z3865 Quintuplet liveborn infant, delivered vaginally

Z3866 Quintuplet liveborn infant, delivered by cesarean

Z3868 Other multiple liveborn infant, delivered vaginally

Z3869 Other multiple liveborn infant, delivered by cesarean

Z387 Other multiple liveborn infant, born outside hospital

Z388 Other multiple liveborn infant, unsp as to place of birth

;

RUN;

 

This code reads in the ICD10 DX code and stops at the first blank character. Great.

 

How do I read the rest of the data as one character variable, such as NBdescription?

 

I will use this technique multiple times for the numerous code/description pairs I will come across.

 

Thanks in advance.

 

Stephen Dybas


Accepted Solutions
Solution
‎09-13-2016 11:09 AM
Super User
Posts: 5,079

Re: Input statement: How do I read multiple words as one string variable.

Here's something you could try:

 

data want;

length nbDescription $ 200;

input dx $ nbDescription $ &;

datalines;

....

;

 

 

View solution in original post


All Replies
Super User
Posts: 6,928

Re: Input statement: How do I read multiple words as one string variable.

Use a sufficiently long informat to force formatted input, and the truncover option:

data test;
infile cards truncover;
input DX $100.;
cards;
A33 Tetanus neonatorum
E8411 Meconium ileus in cystic fibrosis
H04531 Neonatal obstruction of right nasolacrimal duct
H04532 Neonatal obstruction of left nasolacrimal duct
H04533 Neonatal obstruction of bilateral nasolacrimal duct
H04539 Neonatal obstruction of unspecified nasolacrimal duct
N470 Adherent prepuce, newborn
Z00110 Health examination for newborn under 8 days old
Z00111 Health examination for newborn 8 to 28 days old
Z3800 Single liveborn infant, delivered vaginally
Z3801 Single liveborn infant, delivered by cesarean
Z381 Single liveborn infant, born outside hospital
Z382 Single liveborn infant, unspecified as to place of birth
Z3830 Twin liveborn infant, delivered vaginally
Z3831 Twin liveborn infant, delivered by cesarean
Z384 Twin liveborn infant, born outside hospital
Z385 Twin liveborn infant, unspecified as to place of birth
Z3861 Triplet liveborn infant, delivered vaginally
Z3862 Triplet liveborn infant, delivered by cesarean
Z3863 Quadruplet liveborn infant, delivered vaginally
Z3864 Quadruplet liveborn infant, delivered by cesarean
Z3865 Quintuplet liveborn infant, delivered vaginally
Z3866 Quintuplet liveborn infant, delivered by cesarean
Z3868 Other multiple liveborn infant, delivered vaginally
Z3869 Other multiple liveborn infant, delivered by cesarean
Z387 Other multiple liveborn infant, born outside hospital
Z388 Other multiple liveborn infant, unsp as to place of birth
;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 10

Re: Input statement: How do I read multiple words as one string variable.

Thanks Kurt.
Solution
‎09-13-2016 11:09 AM
Super User
Posts: 5,079

Re: Input statement: How do I read multiple words as one string variable.

Here's something you could try:

 

data want;

length nbDescription $ 200;

input dx $ nbDescription $ &;

datalines;

....

;

 

 

Occasional Contributor
Posts: 10

Re: Input statement: How do I read multiple words as one string variable.

Thanks. That's what the switch I was looking for.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 325 views
  • 0 likes
  • 3 in conversation