BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MVanderkloot
Fluorite | Level 6

I have an Excel file with this list - except it is 10,000 rows

----sas-eg-cca-full----
wlo
knak
votte
khu
sdza
pdeb
bmc
chnel
jell
mghe
alleb
----sas-eg-hcs-chaps-full----
cmat
obri
----sas-eg-dca-phe-read----
hswe
----sas-eg-fnihbabr-ship-read----
iagm
grwn

 

Final dataset would be:


wlo                  sas-eg-cca-full
knak                sas-eg-cca-full
votte                sas-eg-cca-full
khu                  sas-eg-cca-full
sdza                sas-eg-cca-full
pdeb                sas-eg-cca-full
bmc                 sas-eg-cca-full
chnel               sas-eg-cca-full
jell                   sas-eg-cca-full
mghe              sas-eg-cca-full
alleb               sas-eg-cca-full
cmat               sas-eg-hcs-chaps-full
obri                 sas-eg-hcs-chaps-full
hswe               sas-eg-dca-phe-read
iagm               sas-eg-fnihbabr-ship-read
grwn               sas-eg-fnihbabr-ship-read 

 

Thanks MARK

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

First let's get your sample into an actual SAS dataset we can work with.  Let's call it HAVE and the variable USERNAME.

data have;
  input username :$80.;
cards;
----sas-eg-cca-full----
wlo
knak
votte
khu
sdza
pdeb
bmc
chnel
jell
mghe
alleb
----sas-eg-hcs-chaps-full----
cmat
obri
----sas-eg-dca-phe-read----
hswe
----sas-eg-fnihbabr-ship-read----
iagm
grwn
;

Then you just need to run a data step that creates a new retained variable, GROUP, that gets assigned the value of USERNAME when it looks like a group name instead of a username.

data want;
  set have;
  if username=:'----' then group=username;
  else output;
  retain group;
run;

Results:

Obs    username                  group

  1     wlo        ----sas-eg-cca-full----
  2     knak       ----sas-eg-cca-full----
  3     votte      ----sas-eg-cca-full----
  4     khu        ----sas-eg-cca-full----
  5     sdza       ----sas-eg-cca-full----
  6     pdeb       ----sas-eg-cca-full----
  7     bmc        ----sas-eg-cca-full----
  8     chnel      ----sas-eg-cca-full----
  9     jell       ----sas-eg-cca-full----
 10     mghe       ----sas-eg-cca-full----
 11     alleb      ----sas-eg-cca-full----
 12     cmat       ----sas-eg-hcs-chaps-full----
 13     obri       ----sas-eg-hcs-chaps-full----
 14     hswe       ----sas-eg-dca-phe-read----
 15     iagm       ----sas-eg-fnihbabr-ship-read----
 16     grwn       ----sas-eg-fnihbabr-ship-read----

If you really want to remove those quadruple dashes you might update the code that sets GROUP.

group=transtrn(username,'----',trimn(' '));

View solution in original post

7 REPLIES 7
MVanderkloot
Fluorite | Level 6

I have checked the community for Ideas - but couldn't find anything - so I don't know what to try.

 

tomrvincent
Rhodochrosite | Level 12
You need to identify the pattern and logic you're trying to achieve. Maybe keep the field as the 2nd column if it starts with '--'...
MVanderkloot
Fluorite | Level 6
I was hoping for a SAS Program that can determine the cells with titles
that need to be repeated in the second column for each user in that part of
the list
Then keep going through the list - as there is no pattern - it is just the
names of the users within each Shared Directory on the SAS Server.
The data is pumped out of our system in this manner - we need to get a
system that we can look at the access of each user.
Tom
Super User Tom
Super User

First let's get your sample into an actual SAS dataset we can work with.  Let's call it HAVE and the variable USERNAME.

data have;
  input username :$80.;
cards;
----sas-eg-cca-full----
wlo
knak
votte
khu
sdza
pdeb
bmc
chnel
jell
mghe
alleb
----sas-eg-hcs-chaps-full----
cmat
obri
----sas-eg-dca-phe-read----
hswe
----sas-eg-fnihbabr-ship-read----
iagm
grwn
;

Then you just need to run a data step that creates a new retained variable, GROUP, that gets assigned the value of USERNAME when it looks like a group name instead of a username.

data want;
  set have;
  if username=:'----' then group=username;
  else output;
  retain group;
run;

Results:

Obs    username                  group

  1     wlo        ----sas-eg-cca-full----
  2     knak       ----sas-eg-cca-full----
  3     votte      ----sas-eg-cca-full----
  4     khu        ----sas-eg-cca-full----
  5     sdza       ----sas-eg-cca-full----
  6     pdeb       ----sas-eg-cca-full----
  7     bmc        ----sas-eg-cca-full----
  8     chnel      ----sas-eg-cca-full----
  9     jell       ----sas-eg-cca-full----
 10     mghe       ----sas-eg-cca-full----
 11     alleb      ----sas-eg-cca-full----
 12     cmat       ----sas-eg-hcs-chaps-full----
 13     obri       ----sas-eg-hcs-chaps-full----
 14     hswe       ----sas-eg-dca-phe-read----
 15     iagm       ----sas-eg-fnihbabr-ship-read----
 16     grwn       ----sas-eg-fnihbabr-ship-read----

If you really want to remove those quadruple dashes you might update the code that sets GROUP.

group=transtrn(username,'----',trimn(' '));
MVanderkloot
Fluorite | Level 6
Thank you for your help - it works perfectly...
Tom
Super User Tom
Super User

If you are reading it directly from a file (or a piped output of another operating system command) then you can take advantage or the DLMSTR= option on the INFILE statement.

data have;
  infile cards dlmstr='----';
  input username :$80.;
  if _infile_=:'----' then group=username;
  else output;
  retain group;
cards;
----sas-eg-cca-full----
wlo
knak
votte
khu
sdza
pdeb
bmc
chnel
jell
mghe
alleb
----sas-eg-hcs-chaps-full----
cmat
obri
----sas-eg-dca-phe-read----
hswe
----sas-eg-fnihbabr-ship-read----
iagm
grwn
;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 1297 views
  • 2 likes
  • 3 in conversation