BookmarkSubscribeRSS Feed
req41273
Quartz | Level 8

I'm using proc sql code to create a table that displays output data as below:

 

phnumber            Attrrecno

444333888 2         389

4328883333        391

8388888833        389

8388283888      391

82383838383    389

99293939393    391

 

My issue is, I need to create separate columns for the data under the phnumber column.  The new columns will contain either a mobile phone number or home phone number based on the value under attrrecno.  If attreccno is 389, it's home number.  If 391 it is mobile.  Using proc sql how do I do this.  Or, can it be done on the output side using SAS EG Query  Builder? I'm sending attachment as well to show my current proc sql code. 

4 REPLIES 4
PaigeMiller
Diamond | Level 26
proc sql;
    create table want as select case when attrrecno=389 then 
              phnumber else . end as home_number,
          select case when attrrecno=391 then phnumber else . end 
                  as mobile_number,
          attrrecno 
     from have;
quit;
--
Paige Miller
req41273
Quartz | Level 8

Will try your suggestion. 

 

Also, received  following suggestion (see attachment doc).  Getting a syntax error regarding the select subqueries.  SAS error says expecting a , ), <>. and, or, between, etc. 

 

Do you see anything wrong with the code syntax in the attachment that would cause this error?

thanks

 

Tom
Super User Tom
Super User

Post a copy of the SAS log with the error message. Do NOT attach a file. Instead use the Insert Code button in the forum editor (looks like {i}) to get a pop-up window that you can use to paste the text lines from the log.

ballardw
Super User

@Tom wrote:

Post a copy of the SAS log with the error message. Do NOT attach a file. Instead use the Insert Code button in the forum editor (looks like {i}) to get a pop-up window that you can use to paste the text lines from the log.


And it is not even a log entry.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1422 views
  • 2 likes
  • 4 in conversation