BookmarkSubscribeRSS Feed
yoyong555
Obsidian | Level 7

Hi everyone. 

 

My data looks something like this:

 

Location            Count1      Count2           Count3

1                        12                                      7

2                        10                  13                2

3                          5

4                          8                  12                15

 

And I want the data to look like this:

 

Location      Count

1                  12

2                  10

3                   5

4                   8

2                  13

4                  12

1                   7

2                   2

4                  15

 

Thanks for your help.

 

 

 

4 REPLIES 4
novinosrin
Tourmaline | Level 20

HI @yoyong555 

 

data have;
input Location            Count1      Count2           Count3;
cards;
1                        12                  .                    7
2                        10                  13                2
3                          5                 .              .
4                          8                  12                15
;

proc transpose data=have out=temp(where=(col1 ne .));
by location;
run;

proc sort data =temp out=want(drop=_name_);
by _name_;
run;
yoyong555
Obsidian | Level 7
Thank you @novinosrin.

Do I need to indicate a . for all the blanks for this to work? I should have only 2 variables but the result had more than 2.

If I have 100 variables (Count1 - Count100), how do I assign a . to all the blanks? Thanks.
novinosrin
Tourmaline | Level 20

Hi @yoyong555  I think you are refering to DATA HAVE step. That was just to create a sample and yes you would have to indicate with a . for missing values especially when you are trying to read raw data using LIST input . But as long as your sample is a representative one of your real, do not be concerned about that.

 

You just need to focus on 

 

proc transpose data=have out=temp(where=(col1 ne .));
by location;
var count:;
run;

proc sort data =temp out=want(drop=_name_);
by _name_;
run;
yoyong555
Obsidian | Level 7
Hi @novinosrin.
Here is the output.

Obs Location _NAME_ COL1
1 1 Count1 12
2 1 Count2 7
3 1 Count3 2
4 3 Count1 5
5 3 Count2 4
6 3 Count3 8

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
  • 4 replies
  • 929 views
  • 0 likes
  • 2 in conversation