data

Reply
Occasional Contributor
Posts: 11

data

data trials1;

input id deptcode salary;

datalines;

1001 FRM 23000

1002 GMM 45090

1003 DFG 23480

1004 TTM 34200

1005 DEE 34000

1006 FRM 45000

1007 GMM 34700

1008 DFG 43000

1009 DFG 23000

1010 TTM 34700

1011 DEE 45022

1012 FRM 90111

1013 GMM 76000

1014 DFG 47800

1015 TTM 45600

1016 DEE 34890

1017 FRM 34500

1018 GMM 35700

1019 DFG 48000

1020 TTM 36700

;

i have a sample data, i am trying to write a code that selects two deptcodes each from the data, any help please, thanks.

Super Contributor
Posts: 543

Re: data

First, you need a dollar sign to tell SAS that department is character;

data trials1;

input id deptcode $ salary;

datalines;

1001 FRM 23000

1002 GMM 45090

...

;

OK, so, what do you need? what two departments would you like to select?

Your question is very vague. Do you need the two departments with the top salary?

or?

Occasional Contributor
Posts: 11

Re: data

Hi, i only to select the first two deptcodes for each deptcode

Super Contributor
Posts: 543

Re: data

You can try this:

proc sort data = trials1;by deptcode;run;

data want;

    set trials1;

    by deptcode;

    retain cnt;

    if first.deptcode then cnt = 1;

        else cnt ++ 1;

    if cnt < 3;

run;

Occasional Contributor epr
Occasional Contributor
Posts: 14

Re: data

Try some thing like this

data trials1;

input id deptcode $ salary;

datalines;

1001 FRM 23000

1002 GMM 45090

1003 DFG 23480

1004 TTM 34200

1005 DEE 34000

1006 FRM 45000

1007 GMM 34700

1008 DFG 43000

1009 DFG 23000

run;

proc sql;

create table want as select * from trials1 group by deptcode having count(deptcode)=2 order by id;

quit;

run;

Ask a Question
Discussion stats
  • 4 replies
  • 208 views
  • 0 likes
  • 3 in conversation