Why the following DATA step doesn't create the correct output?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Why the following DATA step doesn't create the correct output?

[ Edited ]

I want to create a data set as shown below:

data set.png

I used the following (column input) code:

data GYM_UPDATE;
    infile datalines pad;
    input @1 ID @3 Gender $ Age 5-6 Vault 8-10 Floor 12-14 P_BAR 16-18;
    datalines;
3 6.7
5 15 8.1 7.2
7 F
;
run;

The output is strange: 

wrongdataset.png

 

I am able to create the correct data set by using the listing input with comma as the delimiter. However, I still want to figure out what goes wrong in the above column input code. Thanks in advance.


Accepted Solutions
Solution
4 weeks ago
Super User
Posts: 1,228

Re: Why the following DATA step doesn't create the correct output?

You miss gender length - how many characters to input.

Try next code:

 

data GYM_UPDATE;
    infile datalines pad;
    input @1 ID @3 Gender $1. 
                  Age 5-6 Vault 8-10 Floor 12-14 P_BAR 16-18;
    datalines;
3              6.7
5   15 8.1 7.2
7 F
;
run;

View solution in original post


All Replies
Solution
4 weeks ago
Super User
Posts: 1,228

Re: Why the following DATA step doesn't create the correct output?

You miss gender length - how many characters to input.

Try next code:

 

data GYM_UPDATE;
    infile datalines pad;
    input @1 ID @3 Gender $1. 
                  Age 5-6 Vault 8-10 Floor 12-14 P_BAR 16-18;
    datalines;
3              6.7
5   15 8.1 7.2
7 F
;
run;
Occasional Contributor
Posts: 11

Re: Why the following DATA step doesn't create the correct output?

It works, thank you so much!

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 103 views
  • 1 like
  • 2 in conversation