BookmarkSubscribeRSS Feed
SAS_Practice
Calcite | Level 5

I have a following dataset with two variables (var, count):

 

var                                               count
--------------------------                     -------            
Lassion Good Boy                          2
jassion bay boy                               5

Pankha                                          10

 

How can I create a dataset (not proc report, as I will use the result dataset later) without hardcoding as below (an additional row for the variable var), Result dataset should be as below :


var                                    count
----------------                      ------- 
Lassion Good Boy          
Lassion Good Boy               2
jassion bad boy
jassion bad boy                   5

Pankha

Pankha                                10

 

Thank you so much

7 REPLIES 7
Zhanxiong
Obsidian | Level 7
So the "count" variable in the new data set is of type character instead of numeric?
SAS_Practice
Calcite | Level 5

Count should still be numeric. 

Thank you 

Zhanxiong
Obsidian | Level 7
Then you will get a "." instead of blank in "count".
JoshB
Quartz | Level 8

data want(drop=_cnt);
  set have(rename=(count=_cnt));
  output;
  count=_cnt;
  output;
run;
Reeza
Super User

Are you familiar with the OUTPUT statement? That should be all you need for this problem. If order matters, you may want a PROC SORT as well. 

 

And CALL MISSING() as well, to set values to missing is a convenient option. It doesn't matter if the variable is character or numeric. 

 


@SAS_Practice wrote:

I have a following dataset with two variables (var, count):

 

var                                               count
--------------------------                     -------            
Lassion Good Boy                          2
jassion bay boy                               5

Pankha                                          10

 

How can I create a dataset (not proc report, as I will use the result dataset later) without hardcoding as below (an additional row for the variable var), Result dataset should be as below :


var                                    count
----------------                      ------- 
Lassion Good Boy          
Lassion Good Boy               2
jassion bad boy
jassion bad boy                   5

Pankha

Pankha                                10

 

Thank you so much


 

Zhanxiong
Obsidian | Level 7
I guess even with CALL MISSING, you may still not assign a missing numeric value to be blank, as blank has already been reserved to represent missing character values.
Reeza
Super User
You could just set option missing to blank though. It'd definitely doable.

option missing = '';

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