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

Hi ,

 

I have a dataset PROV contaiins variables  provider_id ,provider_name,case_id,year .How do I get below desired output using Prov data set.

 

PROV Data set data:

 provider_id      provider_name     case_id            year

2233              xjlh                        2017-10956      Less than 1 year

2234            xxxx                        2017-10957       Less than 1 year

2235             yyyy                        2017-10958      Less than 1 year

2236             zzzz                        2016-10959      1-2 years old

2236             pppp                        2016-10960     1-2 years old

 

Desired output :

provider_id  provider_name case_id 

2233                 xjlh              2017-10956

2234                xxxx             2017-10957

2235                yyyy               2017-10958

----------------------------------------------------

Less than 1 year                    3

---------------------------------------------------

2236               zzzz               2016-10959  

2236                pppp             2016-10960  

------------------------------------------------------

1-2 years old                         2

-----------------------------------------------

 

 

Regards,

chandu

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

First of all, the proper way to present sample data is a data step, as

data prov;
infile cards dlm=',';
input provider_id provider_name $ case_id :$10. year :$20.;
cards;
2233,xjlh,2017-10956,Less than 1 year
2234,xxxx,2017-10957,Less than 1 year
2235,yyyy,2017-10958,Less than 1 year
2236,zzzz,2016-10959,1-2 years old
2236,pppp,2016-10960,1-2 years old
;
run;

This lets everybody recreate your dataset with copy/paste and run, regardless of SAS versions etc.

A macro to help in converting existing datasets to a data step can be found here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

From that, I ran

proc report data=prov;
column provider_id provider_name case_id year provider_id=count;
define year / group order=data noprint;
define provider_id / display;
define provider_name / display;
define case_id / display;
define count / n noprint;
break after year /summarize;
compute after year;
  line year $20. count 5.;
endcomp;
run;

and came pretty close to your intended result (here in listing form):

provider_  provider            
       id  _name     case_id   
     2233  xjlh      2017-10956
     2234  xxxx      2017-10957
     2235  yyyy      2017-10958
   Less than 1 year        3   
     2236  zzzz      2016-10959
     2236  pppp      2016-10960
   1-2 years old           2   

 

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

First of all, the proper way to present sample data is a data step, as

data prov;
infile cards dlm=',';
input provider_id provider_name $ case_id :$10. year :$20.;
cards;
2233,xjlh,2017-10956,Less than 1 year
2234,xxxx,2017-10957,Less than 1 year
2235,yyyy,2017-10958,Less than 1 year
2236,zzzz,2016-10959,1-2 years old
2236,pppp,2016-10960,1-2 years old
;
run;

This lets everybody recreate your dataset with copy/paste and run, regardless of SAS versions etc.

A macro to help in converting existing datasets to a data step can be found here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

From that, I ran

proc report data=prov;
column provider_id provider_name case_id year provider_id=count;
define year / group order=data noprint;
define provider_id / display;
define provider_name / display;
define case_id / display;
define count / n noprint;
break after year /summarize;
compute after year;
  line year $20. count 5.;
endcomp;
run;

and came pretty close to your intended result (here in listing form):

provider_  provider            
       id  _name     case_id   
     2233  xjlh      2017-10956
     2234  xxxx      2017-10957
     2235  yyyy      2017-10958
   Less than 1 year        3   
     2236  zzzz      2016-10959
     2236  pppp      2016-10960
   1-2 years old           2   

 

Ksharp
Super User
data PROV;
input  provider_id     ( provider_name     case_id            year) (& $20.);
cards;
2233              xjlh                        2017-10956      Less than 1 year
2234            xxxx                        2017-10957       Less than 1 year
2235             yyyy                        2017-10958      Less than 1 year
2236             zzzz                        2016-10959      1-2 years old
2236             pppp                        2016-10960     1-2 years old
;
run;

proc report data=prov nowd;
column _all_ n ;
define year/order descending noprint;
define n/noprint;
compute after year;
line @1 year $20. @40  n ;
endcomp;
run;
 
Astounding
PROC Star

To get something easily, you can approximate what you asked for:

 

proc print data=have n='Duration' label;

by year;

id year;

var provider_id  provider_name case_id;

label year='Duration';

run;

 

If that's not close enough, it takes a more complex approach (as others have shown)..

chanduk
Obsidian | Level 7
The solution examples which are provided by Ksharp,KurtBremser are working fine

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 937 views
  • 1 like
  • 4 in conversation