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.
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;
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
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.
@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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.