BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Agent1592
Pyrite | Level 9

I have the following data: How can I collapse these two rows into 1 using the SQL procedure:

 

IDTypeRateAmtTrendeventfinalcarryovercomment
1A2     Text1
1B0.7 decreasing0.625  Text2
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data have;
   input ID Type $ Rate Amt $ Trend :$20. event	final	carryover comment $;
   infile datalines dlm = ',';
   datalines;
1,A,2  , ,          , , ,     ,Text1
1,B,0.7, ,decreasing, , ,0.625,Text2
;

proc sql;
   create table want as
   select ID
         ,count(ID) as Count label = 'Count Number of Type'
   from have
   group by ID;
quit;

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20
Why limit yourself to SQL?
Also how do you want to collapse since there are different values in the same column?
Pls provide a want data set.
Data never sleeps
Agent1592
Pyrite | Level 9

I do not necessarily need SQL. I just want to count the number By Type: This is my want table.

IDCount Number of Type
12
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data have;
   input ID Type $ Rate Amt $ Trend :$20. event	final	carryover comment $;
   infile datalines dlm = ',';
   datalines;
1,A,2  , ,          , , ,     ,Text1
1,B,0.7, ,decreasing, , ,0.625,Text2
;

proc sql;
   create table want as
   select ID
         ,count(ID) as Count label = 'Count Number of Type'
   from have
   group by ID;
quit;
PeterClemmensen
Tourmaline | Level 20

I agree with @LinusH, but if you absolutely have to do this in sql you have to make the decision of what value you want in eg Type and Rate? 🙂 

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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