BookmarkSubscribeRSS Feed
sahoositaram555
Pyrite | Level 9

Hi everyone, i have a table as below. i want to categorize the var_details variable by taking the maximum and minimum values from i variable. Eg: a new variable lets say category should be created where Age,Mean(SD),Median(Q1-Q3),RANGE should be tagged as 1 then for Height(should be tagged as 2 for 3 rows ) and subsequently for other variables depends on the statistical attributes they are having. any suggestion how to proceed with the use of DO loops or any other simple methods to go ahead.     

 demog.jpg

 

 

6 REPLIES 6
unison
Lapis Lazuli | Level 10

Hi,

 

can you show a table of what you want like you have done with the data you have. That way it’s a little more clear as to what you’re envisioning.

 

Thanks,

 

-unison

-unison
sahoositaram555
Pyrite | Level 9

Hi @unison;

i wanted an output something like below posted picture :

So, i  have 4 main categories age ,height , occupation ,days(diffrently color coded) . every categories have different statistical parameters as required like mean(SD), Median(Q1-Q3) is common to all categories but some categories like occupation has additional parameters like variance , mode etc. FYI, value columns are not blank(had to hide due to policy issues). 

 i want to create a new variable named Order which will assign a unique number to each category and it will differ from category due to difference in number of statistical parameters as mentioned above. Eg: Age and it's mean(SD), Median(Q1-Q3),RANGE must be grouped to assign a number 1(in total total those first 4 rows colored in light green must be 1 for all Order observation. but the moment it goes to height the Order number should changed to 2 till it reaches its range(the row just before occupation.

 

Hope it's clear now. 

demog.jpg

unison
Lapis Lazuli | Level 10

Is this right? This solution assumes an order like you have.

 

data have;
	length var_details $20.;
	input var_details $ values i;
	datalines;
age . 1
mean 1 2
stdev 2 3
range 3 4
height . 1
mean 11 2
stdev 26 3
range 32 4
iqr 32 5
occupation . 1
mean 42 2
;
run;

data want;
	set have;
	retain category 0;

	if values=. then
		category+1;
run;

-unison

-unison
Kurt_Bremser
Super User

Please post existing data in a data step with datalines. Pictures are only good to show intended results, as these can be evaluated with the old Eyeball Mk1.

DO NOT post data as pictures. Unless you think somebody hired us to do the typing for you.

sahoositaram555
Pyrite | Level 9
Dear @Kurt_Bremser,
didn't mean anything like you have thought of . I just took a chunk of data and changed the values which i had to. Well, i would take your reply as a note of advice and will implement form my next query.
ed_sas_member
Meteorite | Level 14

Something like this ?

 

data want1;
	set have;
	retain category;
	if i = 1 then do;
		category = Var_details;
		delete;
	end;
run;

/* OR */

data want2;
	set have;
	retain category;
	if i = 1 then do;
		category + 1;
		delete;
	end;
run;

 

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 991 views
  • 1 like
  • 4 in conversation