DATA Step, Macro, Functions and more

How to compare values within the variable

Reply
Contributor
Posts: 35

How to compare values within the variable

Hello,

Am in middle of some project and am trying to find a logic for the below. Please advise.

Dataset

col1  col2  col3

123 

123  001

123  001

456

456  101

123

123  033

123  101

456

456  001

456  001

there are set of numbers in col1 and some 3 dig codes in col2 which starts with a blank value. I need the unique set of codes(col2) which are either repetitive or non repetitve. all the unique sets needs to be printed either into new variable or a new dataset. Please advise.

Super User
Super User
Posts: 7,942

Re: How to compare values within the variable

Hi,

Not sure I am quite following you.  Numbers cannot have a blank value?  For duplicates, use:

proc sort data=have out=want (keep=col2) nodupkey;

     by col2;

run;

Super User
Posts: 11,343

Re: How to compare values within the variable

Please provide what you would expect the output to look like as there are several ways to interpret your written requirement.

Contributor
Posts: 35

Re: How to compare values within the variable

Hello,

The dataset I have looks like:

NumberSet_of_codes
123456.
123456001
123456001
456789.
456789022
456789001
456789339
456789010
456789022
456789110
456789110
789102.
789102111
789102110
789102022
123456.
123456022
123456001
123456339
123456010
123456022
123456110
123456110
456789.
456789001
456789001

Expected Output is :

NumberSet_of_codesunique_set_of_codesCount
123456..3
123456001001
123456001001
456789..
456789022022
456789001001
456789339339
456789010010
456789022022
456789110110
456789110110
789102..
789102111111
789102110110
789102022022
123456.
123456022
123456001
123456339
123456010
123456022
123456110
123456110
456789.
456789001
456789001

Every sequence of code starts with a blank. Need to identify such unique sets based on card numbers in col1 and the unique set count.

Many thanks in advance.

Frequent Contributor
Posts: 130

Re: How to compare values within the variable

In addition to RW9's response using the nodupkey in the sort procedure you can also use the select distinct in a sql procedure:

proc sql;

create table want as

select unique col2

from have;

quit;

Contributor
Posts: 35

Re: How to compare values within the variable

Hello,

sorry for the confusion, Below is the detailed explanation:

NumberSet_of_codes
123456.
123456001
123456022
456789.
456789022
456789022
456789339
456789068
456789110
456789001
123456.
123456010
123456022
123456339
123456068
3598754.
3598754001
3598754022
456789.
456789339
3598754.
3598754339

Above table contains number and some set of codes(starts with missing values). one set of code is for one card number (number). I need to find the unique set of codes in that column (set of codes) as below:

expected:

unique_set_of_codesUnique_Count
.4
001
022
.
022
022
339
068
110
001
.
010
022
339
068
.
339

Thanks in advance.

Contributor
Posts: 35

Re: How to compare values within the variable

Hello,

The dataset that I have looks like:

NumberSet_of_codes
123456.
123456001
123456001
456789.
456789022
456789001
456789339
456789010
456789022
456789110
456789110
789102.
789102111
789102110
789102022
123456.
123456022
123456001
123456339
123456010
123456022
123456110
123456110
456789.
456789001
456789001

Expected Output is :

NumberSet_of_codesunique_set_of_codesCount
123456..3
123456001001
123456001001
456789..
456789022022
456789001001
456789339339
456789010010
456789022022
456789110110
456789110110
789102..
789102111111
789102110110
789102022022
123456.
123456022
123456001
123456339
123456010
123456022
123456110
123456110
456789.
456789001
456789001

Every sequence of code starts with a blank. Need to identify such unique sets based on card numbers in col1 and the unique set count.

Note: There might be double missing values in sequence in between the data (col2) instead of single missing value.

Many thanks in advance.

Respected Advisor
Posts: 4,173

Re: How to compare values within the variable

Your expected output has the same number of rows like your "have" data. The values for "Set_of_codes" are identical to "unique_set_of_codes". I don't understand what you want to do here. I also don't understand what you count of 3 is based on.

Contributor
Posts: 35

Re: How to compare values within the variable

I need only col3 and col4 in the output. the count 3 is nothing but the count of unique set of codes.

Ask a Question
Discussion stats
  • 8 replies
  • 337 views
  • 0 likes
  • 5 in conversation