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

Hi All, 

 

So I am reading a .csv file into SASUniversity and I am having an issue. All of the data should be numeric with exception to a handful. For some reason they are reading in as the first have Character and the last half numeric. I have my code below, is there a post-fix or something I need to add to get these to read in as numeric? For reference, the variable names that follow with $8 are those that are supposed to be character, everything else should be numeric. 

 

Any help would be appreciated! 

 

data IHC.main;
infile '/folders/myfolders/IHC/EMainTable.csv' firstobs=2 dlm=',' lrecl=32000 truncover DSD;
length Newid Icupt Dschrg_dspstn_cd Mortly_indctr_cd Primdischdiagcd
Primdishdiag $8 Admitdiagcd1 Admitdiag1 $8 Male Age Imrs Imrsgroup
Imrsgroup3 Rvitestresult Cvhx Hearrate Resprate Sbp dbp Bmi
Minapache Maxapache Hypertensionhx Hyperlipidemiahx Diabhx
Mihx Cadhx Cvahx Tobaccohx Pttype $8 Afibhx Dysrhythmiahx
Chfhx Copdhx Respfailhx Renalfailhx Liverfailhx Tiahx
Alcoholabusehx Drugabusehx Race $8 Pneumonia Adeno H1ni Hmpv
Flua Flub Para Rhino Rsv Corona Bnppreclosest Bnppremax
Bnpindexhospmax Bnpost90dymax Esrindexhospax Gfrindexhospmin
Tropiindexhospmax Tropipost90dymax Sp02indexhospmin
Staphaureusindexhosp Streppneumoindexhosp Afibindexhosp
Chestpainindexhosp Chfindexhosp Cvaindexhosp Dysrhythmiaindexhosp
Fallindexhosp Liverfailindexhosp Malaiseindexhosp Miindexhosp
Respfailindexhosp Sepsisindexhosp Sobindexhosp Wheezeindexhosp
Coughindexhosp Sputum Feverindexhosp Temp Fever Wbc Dxleukocytosis
Leukosytosis Crphsindexhospmax Elevatedcrp Dxhypoxemia Hypoxemia
Anydrug Antibiotic Anticoagulant Anticoagulantother Antiplatelet
Antiviral Betablocker Ccb Corticosteriod Statin Warfarin Fvc
Fivc Tlc Frc_n2 Fef25_75 Pef Fev1 Fev2 Fev3 Fev5 Fev6 Fev75
Dlco Vc Upperrespinfection Tuberculosis Bronchiolitis
Bronchitis Bacterialpneumonia Viralpneumonia Infectiouspneumonia
Influenza Infection Anypneumtest Pntestresult $8 Cpneumo Npneumo
Streppneumo Anybactest Anybacpositive Anylungbactest
Lungbacpositive dead Cvdeathhosp Timetodeath Cvprimcauseofdeath
Cvaprimcod Miprimcod Mifu Timetomi Cvafu Timetocva Chfifu
timetochf ;
input Newid Icupt Dschrg_dspstn_cd Mortly_indctr_cd Primdischdiagcd
Primdishdiag Admitdiagcd1 Admitdiag1 Male Age Imrs Imrsgroup
Imrsgroup3 Rvitestresult Cvhx Hearrate Resprate Sbp dbp Bmi
Minapache Maxapache Hypertensionhx Hyperlipidemiahx Diabhx
Mihx Cadhx Cvahx Tobaccohx Pttype Afibhx Dysrhythmiahx
Chfhx Copdhx Respfailhx Renalfailhx Liverfailhx Tiahx
Alcoholabusehx Drugabusehx Race Pneumonia Adeno H1ni Hmpv
Flua Flub Para Rhino Rsv Corona Bnppreclosest Bnppremax
Bnpindexhospmax Bnpost90dymax Esrindexhospax Gfrindexhospmin
Tropiindexhospmax Tropipost90dymax Sp02indexhospmin
Staphaureusindexhosp Streppneumoindexhosp Afibindexhosp
Chestpainindexhosp Chfindexhosp Cvaindexhosp Dysrhythmiaindexhosp
Fallindexhosp Liverfailindexhosp Malaiseindexhosp Miindexhosp
Respfailindexhosp Sepsisindexhosp Sobindexhosp Wheezeindexhosp
Coughindexhosp Sputum Feverindexhosp Temp Fever Wbc Dxleukocytosis
Leukosytosis Crphsindexhospmax Elevatedcrp Dxhypoxemia Hypoxemia
Anydrug Antibiotic Anticoagulant Anticoagulantother Antiplatelet
Antiviral Betablocker Ccb Corticosteriod Statin Warfarin Fvc
Fivc Tlc Frc_n2 Fef25_75 Pef Fev1 Fev2 Fev3 Fev5 Fev6 Fev75
Dlco Vc Upperrespinfection Tuberculosis Bronchiolitis
Bronchitis Bacterialpneumonia Viralpneumonia Infectiouspneumonia
Influenza Infection Anypneumtest Pntestresult Cpneumo Npneumo
Streppneumo Anybactest Anybacpositive Anylungbactest
Lungbacpositive dead Cvdeathhosp Timetodeath Cvprimcauseofdeath
Cvaprimcod Miprimcod Mifu Timetomi Cvafu Timetocva Chfifu
timetochf;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

In a LENGTH statement, any instructions (such as $8) applies to the complete list of variable names that came before.  So you will need to change the LENGTH statement.  Just looking at the beginning of it, you now have:

 

length Newid Icupt Dschrg_dspstn_cd Mortly_indctr_cd Primdischdiagcd
Primdishdiag $8 Admitdiagcd1 Admitdiag1 $8

 

You would need to change that to:

 

length Newid Icupt Dschrg_dspstn_cd Mortly_indctr_cd Primdischdiagcd 8
Primdishdiag $8 Admitdiagcd1 8 Admitdiag1 $8

 

Using 8 as the length will make the variables that precede it numeric.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

In a LENGTH statement, any instructions (such as $8) applies to the complete list of variable names that came before.  So you will need to change the LENGTH statement.  Just looking at the beginning of it, you now have:

 

length Newid Icupt Dschrg_dspstn_cd Mortly_indctr_cd Primdischdiagcd
Primdishdiag $8 Admitdiagcd1 Admitdiag1 $8

 

You would need to change that to:

 

length Newid Icupt Dschrg_dspstn_cd Mortly_indctr_cd Primdischdiagcd 8
Primdishdiag $8 Admitdiagcd1 8 Admitdiag1 $8

 

Using 8 as the length will make the variables that precede it numeric.

ScottSt
Fluorite | Level 6

That did it! Thank you so much, I searched and searched but I couldn't figure out how to do that. 

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!

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
  • 2 replies
  • 435 views
  • 2 likes
  • 2 in conversation