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

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
sas_td2016
Obsidian | Level 7

Great.  It works fine.  

 

Thanks lot.

View solution in original post

8 REPLIES 8
art297
Opal | Level 21

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

 

 

 

sas_td2016
Obsidian | Level 7

Thanks for your reply.  

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

art297
Opal | Level 21

That's what the code I suggested does.

 

Art, CEO, AnalystFinder.com

 

sas_td2016
Obsidian | Level 7

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

Astounding
PROC Star

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

;

sas_td2016
Obsidian | Level 7

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.

 

Astounding
PROC Star

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.

sas_td2016
Obsidian | Level 7

Great.  It works fine.  

 

Thanks lot.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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