Search code examples
sas4gl

SAS 4GL - multiple informats


Im learning 4Gl and I have little problem with informats: I have file:

Imie;Nazwisko;Wiek;indeks;PESEL;Kierunek;Rok;Urodziny;Srednia;Frekwencja
Tomasz;Szan;23;114132;9134765445;Informatyka;5;5.32;99%;14.03.91
Karolina;Herl;21;134294;93543245;;3;4.57;92%;29.09.93
Damian;Kwak;24;189994;1234567890;Informatyka;5;3.50;80%;24.09.90
Ebenezer;Scrooge;AA;882741;78899609;Automatyka;4;3.72;34%;30.02.88

And 4GL code:

DATA projekt.project1;
length PESEL $ 11;
length nazwisko $ 15;
length kierunek $ 15;

INFILE 'c:\lasa_do_sasa\studenty.txt' DLM=';' MISSOVER DSD FIRSTOBS=2;
INPUT imie $ nazwisko $ wiek $ nr_indeksu PESEL $ kierunek $ rok srednia_ocen frekwencja PERCENT3. urodziny ddmmyy8. ;

RUN;

The problem is that: if I have xx%;date SAS won't read date. Im getting error: Invalid data for urodziny

anyone could help me? I tihnk Im doind something obvious...


Solution

  • The trick here is to use the : format modifier to stop SAS trying to read beyond the next delimiter after the % sign. You can also set the lengths of your other variables on the input statement this way:

    data want;
    infile cards4 dsd dlm = ';' firstobs = 2;
    input imie $ nazwisko :$15. wiek $ indeks $ PESEL :$11. kierunek :$15. rok urodziny srednia :PERCENT3. frekwencja ddmmyy8. ;
    format frekwencja ddmmyy8.;
    cards4;
    Imie;Nazwisko;Wiek;indeks;PESEL;Kierunek;Rok;Urodziny;Srednia;Frekwencja
    Tomasz;Szan;23;114132;9134765445;Informatyka;5;5.32;99%;14.03.91
    Karolina;Herl;21;134294;93543245;;3;4.57;92%;29.09.93
    Damian;Kwak;24;189994;1234567890;Informatyka;5;3.50;80%;24.09.90
    Ebenezer;Scrooge;AA;882741;78899609;Automatyka;4;3.72;34%;30.02.88
    ;;;;
    run;