BookmarkSubscribeRSS Feed
BartDekeyser
Calcite | Level 5

Hi all ,

 

i have the following Excel  

0116

01161

01161A

01161A1

01161A2

01161B

01161B1

 

and so on. How can i manipulate my data to only keep the lowest sublevel meaning for this case : 

 

01161A1

01161A2

01161B1

 

The file contains 1000+ .

3 REPLIES 3
Kurt_Bremser
Super User

I have no idea how you do that in Excel, but in SAS you can use this SQL step:

proc sql;
create table want as
  select *
  from have
  having length(string) = max(length(string))
;
quit;

 

BartDekeyser
Calcite | Level 5

hmm this will only work if all sublevel have the same length but they dont.

 

Ill give a more detailed example : 

 

0116

01161

01161A

01161A1

01161A2

01161B

01161B1

01161C

01161D

01162

01163

01163A

 

and so on. With you solutions i would only keep : 01161A1, 01161A2,01161B1. But i actually i would like to have those but also : 01161C, 01161D, 01162, 01163A

 

(for sas your sql could be copied right away ^^

 

ballardw
Super User

@BartDekeyser wrote:

hmm this will only work if all sublevel have the same length but they dont.

 

Ill give a more detailed example : 

 

0116

01161

01161A

01161A1

01161A2

01161B

01161B1

01161C

01161D

01162

01163

01163A

 

and so on. With you solutions i would only keep : 01161A1, 01161A2,01161B1. But i actually i would like to have those but also : 01161C, 01161D, 01162, 01163A

 

(for sas your sql could be copied right away ^^

 


My first thought with the original post was "This is not a clearly defined "lowest level"." And your expanded reference data confirms that. Which indicates to me that you have multiple values in a single variable and may perhaps need to parse out the base value, first sublevel, second sublevel (and as many identifiable sublevels as you may have into separate variables (temporarily) to process and then select.

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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 741 views
  • 1 like
  • 3 in conversation