Elisa Venturi
Elisa Venturi

Reputation: 19

SAS load file txt

can you hel me??

I have a txt file:

1 1 8 2 004 149 44.9 Brabant
14 7 7 9 9
32 10 13.5 165 20 7 21 19.9 7
1 1 9 2 004 133 32.5 Liege
12 7 6 11 8
14 18 20.9 140 22.9 18 15 4.4 5

where in the first three lines were analyzed the same ID and the variables analyzed are:

anne, sex, nat, age, prov, tai, pds, ptr, pbi, pss, psi, pmo, dyn, efl, fp, 
slo, cna, flt, rsa, sbf, ll.

how can I loaded the file in SAS and give the names of rows and columns?

THAK YOU VERY MUCH and sorry!!! elisa

Upvotes: 0

Views: 223

Answers (3)

uzbad
uzbad

Reputation: 124

I guess what the issue could have been is more than word in location name. You can overcome it in a following way (assuming longest name to be less than 200 characters):

data data2004; 
  infile 'C:\Users\acer\STAT2012\data2004.txt' truncover;
  input ID
    anne sex nat $ age prov tai pds $200.;
  input ptr pbi pss psi pmo ;
  input dyn efl fp slo cna flt rsa sbf ll;
run;

Upvotes: 0

BellevueBob
BellevueBob

Reputation: 9618

It sounds like your input file has three lines of data for one observation; I reformatted your original question as I think you intended.

If that's true, you just need to read all three lines in one INPUT statement, using the / operator to skip to the next line. In other words, try this:

data STAT2012.data2004; 
    infile 'C:\Users\acer\STAT2012\data2004.txt';
    input ID
          anne sex nat $ age prov tai pds $ 
        / ptr pbi pss psi pmo 
        / dyn efl fp slo cna flt rsa sbf ll;
run;

Of course, you should really be sure the variable names match your file and that the results are as you need. I've given you a very basic example just to get you started.

UPDATE: My example was based on the sample data you posted. I assumed that the first column was an ID variable, since otherwise your sample data had more values than your example.

The best approach in your case would be to use an INFORMAT statement to define how each variable should be read. That will require that you understand the types (character or numeric) of each variable, and the maximum length of each character variable. For numeric variables, you can just use the best32. informat. If you really do not know the maximum length of the character variables, you can try using $200., which will make each variable 200 character long.

For example:

data STAT2012.data2004; 
    infile 'C:\Users\acer\STAT2012\data2004.txt';

    /* Define the variables that will be read */
    informat 
    /* First line, 8 variables */
          anne  best32.
          sex   $1.
          nat   $4.
          age   best32.
          prov  best32.
          tai   best32.
          pds   best32.   
          ptr   $200.  /* 8th field in your sample, apparently character */

    /* Second line, 5 variables */
          pbi   best32.
          pss   best32.
          psi   best32.
          pmo   best32.
          dyn   best32.

    /* Third line, 9 variables */
          efl   best32.
          fp    best32.
          slo   best32.
          cna   best32.
          flt   best32.
          rsa   best32.
          sbf   best32.
          ll    best32.
         unkn   best32.;  /* an unknown variable I invented */

    /* Input the variables in the order they appear in the file.*/
    input anne sex nat age prov tai pds pdr 
        / pbi pss psi pmo dyn 
        / efl fp slo cna flt rsa sbf ll unkn;
run;

Note that you do not need the DLM option on your INFILE statement. Also note that this example does not read all the data in the sample data you provided; I invented a new variable.

The important thing to remember is to read the variables in the correct order as they appear in your source file.

Upvotes: 1

Elisa Venturi
Elisa Venturi

Reputation: 19

data STAT2012.data2004; 
    infile 'C:\Users\acer\STAT2012\data2004.txt' dlm=' ';
    input 
          anne 1-4  sex $6   nat $8  age 10 prov @$11-21 tai @23  pds @25
        / ptr 1-2 pbi 4 pss 6 psi 8 pmo 10
        /dyn 1-2 efl 4-5 fp 7-10 slo 12-14 cna 16-17 flt 19 rsa 21-22 sbf 24-27 ll 29;
run;

Upvotes: 0

Related Questions