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 = '';

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1730 views
  • 1 like
  • 4 in conversation