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
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(' '));
I have checked the community for Ideas - but couldn't find anything - so I don't know what to try.
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(' '));
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
;
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!
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.
Ready to level-up your skills? Choose your own adventure.