DATA Step, Macro, Functions and more

wide to narrow data?

Accepted Solution Solved
Reply
Super Contributor
Posts: 383
Accepted Solution

wide to narrow data?

I have a census population by counties and age categories in wide format as shown in the Image 2. Can you please help organize it to a narrow format in Image1?

 

I tried e.g.,: if agecat1 then agecat=1; else

                   if agecat2 then agecat=2; else ..

which creates only agecat=1.

 

Image 1: data I want:

wanted.png

Image 2: data I have

have.png


Accepted Solutions
Solution
‎01-28-2018 09:07 PM
Super Contributor
Posts: 383

Re: wide to narrow data?

Posted in reply to novinosrin
Thanks a lot. Below just worked out.
proc transpose data=c.temp out=c.temp1;
by countycode;
run;

View solution in original post


All Replies
Super User
Posts: 2,049

Re: wide to narrow data?

Cruise, you should be on cruise control with proc transpose with tons of syntax on  a google search

Solution
‎01-28-2018 09:07 PM
Super Contributor
Posts: 383

Re: wide to narrow data?

Posted in reply to novinosrin
Thanks a lot. Below just worked out.
proc transpose data=c.temp out=c.temp1;
by countycode;
run;
Super User
Posts: 2,049

Re: wide to narrow data?

Well done! That's the spirit. Have a good evening. Mark your own answer as correct and please close the thread. Good job mate!

Super Contributor
Posts: 383

Re: wide to narrow data?

Posted in reply to novinosrin
do you know how to close the thread?
Super User
Posts: 2,049

Re: wide to narrow data?

Well, you have. Some original posters never mark an answer and the question stays open for ages. I would assume they want more responses, however if it's simple i seriously wonder why they lack the common sense to know that they are not gonna get any more. lol. Marking the answer is closing the thread.

 

I'm sure somebody may still come to this thread and offer like, "hey, here is an array solution. lol" that's like peanuts alongside my beer seeing such messages Smiley Happy

Super Contributor
Posts: 383

Re: wide to narrow data?

Posted in reply to novinosrin
Gotcha. Have a wonderful evening.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 134 views
  • 3 likes
  • 2 in conversation