Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Plzzz Need Help

Status
Not open for further replies.

dearsamuna

Programmer
Sep 14, 2012
3
0
0
Thanks in advance.

Input data is

SampleId sal dob phone

10-1xxx-001 37645 04/23/1978 728364539
10-2xxx-002 38746 05/23/1967 938746355
10-4yyy-511 49875 01/11/1987 938874653
10-2zzz-411 48765 02/22/1954 763542317
10-3xxx-003 48746 05/21/1987 883736335

Output should be like below

SampleId sal dob phone

10-1xxx-001 37645 04/23/1978 728364539
10-2xxx-002 38746 05/23/1967 938746355
10-4yyy-511 49875 01/11/1987 938874653
10-2zzz-411 48765 02/22/1954 763542317
10-3xxx-003 48746 05/21/1987 883736335
20-1xxx-001 37645 04/23/1978 728364539
20-2xxx-002 38746 05/23/1967 938746355
20-4yyy-511 49875 01/11/1987 938874653
20-2zzz-411 48765 02/22/1954 763542317
20-3xxx-003 48746 05/21/1987 883736335
30-1xxx-001 37645 04/23/1978 728364539
30-2xxx-002 38746 05/23/1967 938746355
30-4yyy-511 49875 01/11/1987 938874653
30-2zzz-411 48765 02/22/1954 763542317
30-3xxx-003 48746 05/21/1987 883736335
40-1xxx-001 37645 04/23/1978 728364539
40-2xxx-002 38746 05/23/1967 938746355
40-4yyy-511 49875 01/11/1987 938874653
40-2zzz-411 48765 02/22/1954 763542317
40-3xxx-003 48746 05/21/1987 883736335
 
Hi,

This can be done using the macro code.
The sample code would be like below;

data temp;
infile datalines;
input SampleId $11. sal dob mmddyy10. phone $9. ;
datalines;
10-1xxx-001 37645 04/23/1978 728364539
10-2xxx-002 38746 05/23/1967 938746355
10-4yyy-511 49875 01/11/1987 938874653
10-2zzz-411 48765 02/22/1954 763542317
10-3xxx-003 48746 05/21/1987 883736335
;


data temp (drop = cnt prefx);
set temp;

do while cnt lt 5; /* You can change this limit as per requirement */
prefx = input(substr(SampleId, 1,2), best12.) + 10 ;
/* Above step will extract the first two characters of the sampleID and will add 10 to it */
SampleID = put (prefx, $2.) || trim(left(substr(SampleId,3,9);
output;
end;

run;

proc sort data = temp;
by sampleID;
run;

/* NOTE: I havent tried running this code; but it should work fine with minor adjustments at your site */


sasbuddy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top