DATA Step, Macro, Functions and more

List Input or Modified List Input

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

List Input or Modified List Input

Hello Friends

 

Can you please help me on this query?

I want to get out put for the following file using list or modified list input.  

 

2458 Murray, W 72 185 128 12 38 D
2462 Almers, C 68 171 133 10 5 I
2501 Bonaventure, T 78 177 139 11 13 I
2523 Johnson, R 69 162 114 9 42 S
2539 LaMance, K 75 168 141 11 46 D

 

Thanks.

 


Accepted Solutions
Solution
‎02-26-2018 01:45 PM
Contributor
Posts: 22

Re: List Input or Modified List Input

Posted in reply to Astounding

Great.  It works fine.  

 

Thanks lot.

View solution in original post


All Replies
PROC Star
Posts: 8,114

Re: List Input or Modified List Input

Posted in reply to sas_td2016

Not sure what you're asking, but the following might be close to what you're looking for:

data want (drop=x);
  infile cards truncover;
  informat name $20.;
  input @;
  x=anydigit(substr(_infile_,5))+4;
  _infile_=substr(_infile_,1, x-1)||'  '||substr(_infile_,x);
  input id name & x1-x5 z $;
  cards;
2458 Murray, W 72 185 128 12 38 D
2462 Almers, C 68 171 133 10 5 I
2501 Bonaventure, T 78 177 139 11 13 I
2523 Johnson, R 69 162 114 9 42 S
2539 LaMance, K 75 168 141 11 46 D
;

Art, CEO, AnalystFinder.com

 

 

 

Contributor
Posts: 22

Re: List Input or Modified List Input

Thanks for your reply.  

I need to get out as eg, Murray, W in the output.  

PROC Star
Posts: 8,114

Re: List Input or Modified List Input

Posted in reply to sas_td2016

That's what the code I suggested does.

 

Art, CEO, AnalystFinder.com

 

Contributor
Posts: 22

Re: List Input or Modified List Input

Thanks Art for your help and appreciate that, let me try how it work.  

Super User
Posts: 6,542

Re: List Input or Modified List Input

Posted in reply to sas_td2016

Simplest might be to read in the first initial as a separate variable, then tack it on to the last name.  For example:

 

data want;

length lastname $ 15;

input id lastname initial $ n1 n2 n3 n4 n5 c1 $;

name = catx(' ', lastname, initial);

drop lastname initial;

cards;

2458 Murray, W 72 185 128 12 38 D
2462 Almers, C 68 171 133 10 5 I
2501 Bonaventure, T 78 177 139 11 13 I
2523 Johnson, R 69 162 114 9 42 S
2539 LaMance, K 75 168 141 11 46 D

;

Contributor
Posts: 22

Re: List Input or Modified List Input

Posted in reply to Astounding

Thanks and appreciated for your help.  

This is what I get.  

My code:

data want;
length lastname $15.;
input
id lastname initial $ RestHR MaxHR RecHR TimeMin TimeSec Tolerance $;
name = catx('',lastname, initial);
drop lastname initial;
cards;

2458 Murray, W 72 185 128 12 38 D
2462 Almers, C 68 171 133 10 5 I
2501 Bonaventure, T 78 177 139 11 13 I
2523 Johnson, R 69 162 114 9 42 S
2539 LaMance, K 75 168 141 11 46 D
;
run;
proc print;run;

 

Here is the output:

list_output.PNG

How can I get name in the first column after obs?

What is the importance of this line

drop lastname initial;

 

Thanks.

 

Super User
Posts: 6,542

Re: List Input or Modified List Input

Posted in reply to sas_td2016

To get NAME in the first column, add it to the LENGTH statement.  For example:

 

length name $ 20 lastname $ 15;

 

A DROP statement you will need to learn, as part of the basics.  It means that the variables LASTNAME and INITIAL should not become part of the final data set.  They are computed along the way, but should be removed.

Solution
‎02-26-2018 01:45 PM
Contributor
Posts: 22

Re: List Input or Modified List Input

Posted in reply to Astounding

Great.  It works fine.  

 

Thanks lot.

☑ This topic is solved.

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

Discussion stats
  • 8 replies
  • 156 views
  • 0 likes
  • 3 in conversation