BookmarkSubscribeRSS Feed
wheddingsjr
Pyrite | Level 9

Hi all

 

I have a table that has a column that contains numeric variables. I want to create 2 separate tables based on the length of the number. If the number has more than 6 digits it should go in 1 table and all the rest into another. Is that possible? Any assistance would be appreciated.

3 REPLIES 3
wheddingsjr
Pyrite | Level 9
I should have probably posted this as well. This is the query that is used to create the table. The MRN column is the column that I want to separate.
``PROC SQL;
CREATE TABLE ed.mrn_cohort_a AS
SELECT DISTINCT a.*
, C.MRN AS mrn
FROM work.datapull_1 a
LEFT JOIN EPICFIN.COVERAGE b
ON a.member_id= b.SUBSCRIBERID
LEFT JOIN EPICPAT.PATIENT C
ON B.SubscriberPatientID=C.PATIENTID
AND a.member_id ne ''
;QUIT;``
andreas_lds
Jade | Level 19

If you want to check the number of digits, you have to convert the number into a string, then you could use the length-function. But since a number with more than six digits is larger than 999999 you should just check the value. Separating data is only necessary in some very rare cases, so you may want to explain the steps to follow-up so that maybe better solutions can be found.

If you have to separate the data, try the following data-step:

data work.SmallNumbers work.LargerNumbers;
  set have;
  if MRN <= 999999 then output work.SmallNumbers;
  else output work.LargerNumbers;
run;
Astounding
PROC Star
How many digits in 1.234567?
How about -12345678?

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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