BookmarkSubscribeRSS Feed
dtweah
Calcite | Level 5
Hi I am new to SAS. Three days now but have read more than 700 pages. I am into it and loving it. I have tried all the combinations and can't get this right. The original table can be found at http://www.necliberia.org/results/PDFs/NationalProgressiveresultsReport.pdf on page 5. It is titled "Presidential and Vice Presidential election( Ordered by votes Obtained)"
I have been trying to show my input skills but this is tough. The names are arranged by last followed by a comma then first and I want to keep all the variables.

Here is the copy and paste version I have been working with. I ONLY want to use the methods outlined above. Thanks.

WEAH, George Manneh JOHNSON, J. Rudolph Congress for Democratic Change (CDC) 275,265 28.3%
JOHNSON-SIRLEAF, Ellen BOAKAI, Joseph Nyuma Unity Party (UP) 192,326 19.8%
BRUMSKINE, Charles Walker WARD, Amelia Angeline Liberty Party (LP) 135,093 13.9%
TUBMAN, Winston A. SULUNTEH, Jeremiah Congbeh National Democratic Party of Liberia (NDPL) 89,623 9.2%
SHERMAN, Harry Varney Gboto-Nambi FANIA, John Kollehlon Coalition for Transformation of Liberia (COTOL) 76,403 7.8%
MASSAQUOI, Roland Chris Yarkpah PAYGAI, SR., Q. Somah National Patriotic Party (NPP) 40,361 4.1%
KORTO, Joseph D. Z. BARCLAY, JR., James Kollie Liberia Equal Rights Party (LERP) 31,814 3.3%
KROMAH, Alhaji G. V. RUSSELL, SR., Emmanuel Mac All Liberian Coalition Party (ALCOP) 27,141 2.8%
TIPOTEH, Togba-Nah DAHN, Marcus S. G. Alliance for Peace and Democracy (APD) 22,766 2.3%
TUBMAN, William Vacanarat Shadrach WILLIAMS, Garlo Isaac Reformed United Liberia Party (RULP) 15,115 1.6%
MORLU, John Sembe DEMEN, Joseph Omaxline United Democratic Alliance (UDA) 12,068 1.2%
BARNES, Milton Nathaniel HARRIS, Parleh Dargbeh Liberia Destiny Party (LDP) 9,325 1.0%
TOR-THOMPSON, Margaret J. MARSH, SR., J. Rudolph Freedom Alliance Party of Liberia (FAPL) 8,418 0.9%
WOAH-TEE, Joseph Mamadee BROH, I., Samuel Washington Labor Party of Liberia (LPL) 5,948 0.6%
CONNEH, Sekou Damate SALI, Edward Yarkpawolo Progressive Democratic Party (PRODEM) 5,499 0.6%
FARHAT, David M. GBOLLIE, Saah Ciapha Free Democratic Party (FDP) 4,497 0.5%
KIEH, JR., George Klay TOKPA, Alaric Kormu New Deal Movement (NDM) 4,476 0.5%
JALLAH, Armah Zolu SAMMY, SR., Isaac G. National Party of Liberia (NPL) 3,837 0.4%
KPOTO, Robert Momo SINGBE, Sylvester Bondo Union of Liberian Democrats (ULD) 3,825 0.4%
KIADII, George Momodu MCGILL, Washington Shadrack National Vision Party of Liberia (NATVIPOL) 3,646 0.4%
DIVINE, SR., Samuel Raymond MAMU, SR., Jacob Gbanalagaye Independent 3,188 0.3%
REEVES, Alfred Garpee SHERIF, Martin Mohammed Njavola National Reformation Party (NRP) 3,156
Thanks
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
"...tried all the combinations..."

So, shared what you have tried for specific feedback. Also, what is meant by "I ONLY want to use the methods outlined above." I only see references to how NAME is organized -- no mention about input/code methods or techniques.

Your first challenge is that you are working with "delimited" data but it appears that the comma as a delimiter can also appear within a data field (at least once - who knows?).

Also, a HEADER row (even one added by yourself) would be a sort-of ANCHOR with SAS variable names -- if you might consider in the future to use PROC IMPORT.

Again, suggest you share what, if any, code you have tried and get some forum subscriber feedback on that challenge.

Scott Barry
SBBWorks, Inc.
dtweah
Calcite | Level 5
Thanks for attempting. I just mean by 'only' that I want to do it from 'first principles'
The following has landed me the closest since. I had to create some space between the names of the candidates and use &. But am having a few problems with the numeric variables. May be able to figure it out but I would love to have a solution that does not involve manipulating the data set. Here observations are 22 so it can be done but what if they were more.

Here is the code. See if you can run some variations on it.

data election;
infile datalines truncover dlm=" ";
input pcand & $32. vpcand &$33. polparty & $31. votes comma10. percent percent3.;
datalines;
WEAH, George Manneh JOHNSON, J. Rudolph Congress for Democratic Change (CDC) 275,265 28.3%
JOHNSON-SIRLEAF, Ellen BOAKAI, Joseph Nyuma Unity Party (UP) 192,326 19.8%
BRUMSKINE, Charles Walker WARD, Amelia Angeline Liberty Party (LP) 135,093 13.9%
TUBMAN, Winston A. SULUNTEH, Jeremiah Congbeh National Democratic Party of Liberia (NDPL) 89,623 9.2%
SHERMAN, Harry Varney Gboto-Nambi FANIA, John Kollehlon Coalition for Transformation of Liberia (COTOL) 76,403 7.8%
MASSAQUOI, Roland Chris Yarkpah PAYGAI, SR., Q. Somah National Patriotic Party (NPP) 40,361 4.1%
KORTO, Joseph D. Z. BARCLAY, JR., James Kollie Liberia Equal Rights Party (LERP) 31,814 3.3%
KROMAH, Alhaji G. V. RUSSELL, SR., Emmanuel Mac All Liberian Coalition Party (ALCOP) 27,141 2.8%
TIPOTEH, Togba-Nah DAHN, Marcus S. G. Alliance for Peace and Democracy (APD) 22,766 2.3%
TUBMAN, William Vacanarat Shadrach WILLIAMS, Garlo Isaac Reformed United Liberia Party (RULP) 15,115 1.6%
MORLU, John Sembe DEMEN, Joseph Omaxline United Democratic Alliance (UDA) 12,068 1.2%
BARNES, Milton Nathaniel HARRIS, Parleh Dargbeh Liberia Destiny Party (LDP) 9,325 1.0%
TOR-THOMPSON, Margaret J. MARSH, SR., J. Rudolph Freedom Alliance Party of Liberia (FAPL) 8,418 0.9%
WOAH-TEE, Joseph Mamadee BROH, I., Samuel Washington Labor Party of Liberia (LPL) 5,948 0.6%
CONNEH, Sekou Damate SALI, Edward Yarkpawolo Progressive Democratic Party (PRODEM) 5,499 0.6%
FARHAT, David M. GBOLLIE, Saah Ciapha Free Democratic Party (FDP) 4,497 0.5%
KIEH, JR., George Klay TOKPA, Alaric Kormu New Deal Movement (NDM) 4,476 0.5%
JALLAH, Armah Zolu SAMMY, SR., Isaac G. National Party of Liberia (NPL) 3,837 0.4%
KPOTO, Robert Momo SINGBE, Sylvester Bondo Union of Liberian Democrats (ULD) 3,825 0.4%
KIADII, George Momodu MCGILL, Washington Shadrack National Vision Party of Liberia (NATVIPOL) 3,646 0.4%
DIVINE, SR., Samuel Raymond MAMU, SR., Jacob Gbanalagaye Independent 3,188 0.3%
REEVES, Alfred Garpee SHERIF, Martin Mohammed Njavola National Reformation Party (NRP) 3,156
;
proc print;
run;
dtweah
Calcite | Level 5
The following does it but is inefficient. Involves manipulating the data. Would appreciate an alternative solution. But I appreciate how much I learned from the single problem.

data election;
infile datalines truncover dlm=" ";
input pcand & $45. vpcand &$40. polparty & $50. votes & comma9. percent & percent4.;
datalines;
WEAH, George Manneh JOHNSON, J. Rudolph Congress for Democratic Change (CDC) 275,265 28.3%
JOHNSON-SIRLEAF, Ellen BOAKAI, Joseph Nyuma Unity Party (UP) 192,326 19.8%
BRUMSKINE, Charles Walker WARD, Amelia Angeline Liberty Party (LP) 135,093 13.9%
TUBMAN, Winston A. SULUNTEH, Jeremiah Congbeh National Democratic Party of Liberia (NDPL) 89,623 9.2%
SHERMAN, Harry Varney Gboto-Nambi FANIA, John Kollehlon Coalition for Transformation of Liberia (COTOL) 76,403 7.8%
MASSAQUOI, Roland Chris Yarkpah PAYGAI, SR., Q. Somah National Patriotic Party (NPP) 40,361 4.1%
KORTO, Joseph D. Z. BARCLAY, JR., James Kollie Liberia Equal Rights Party (LERP) 31,814 3.3%
KROMAH, Alhaji G. V. RUSSELL, SR., Emmanuel Mac All Liberian Coalition Party (ALCOP) 27,141 2.8%
TIPOTEH, Togba-Nah DAHN, Marcus S. G. Alliance for Peace and Democracy (APD) 22,766 2.3%
TUBMAN, William Vacanarat Shadrach WILLIAMS, Garlo Isaac Reformed United Liberia Party (RULP) 15,115 1.6%
MORLU, John Sembe DEMEN, Joseph Omaxline United Democratic Alliance (UDA) 12,068 1.2%
BARNES, Milton Nathaniel HARRIS, Parleh Dargbeh Liberia Destiny Party (LDP) 9,325 1.0%
TOR-THOMPSON, Margaret J. MARSH, SR., J. Rudolph Freedom Alliance Party of Liberia (FAPL) 8,418 0.9%
WOAH-TEE, Joseph Mamadee BROH, I., Samuel Washington Labor Party of Liberia (LPL) 5,948 0.6%
CONNEH, Sekou Damate SALI, Edward Yarkpawolo Progressive Democratic Party (PRODEM) 5,499 0.6%
FARHAT, David M. GBOLLIE, Saah Ciapha Free Democratic Party (FDP) 4,497 0.5%
KIEH, JR., George Klay TOKPA, Alaric Kormu New Deal Movement (NDM) 4,476 0.5%
JALLAH, Armah Zolu SAMMY, SR., Isaac G. National Party of Liberia (NPL) 3,837 0.4%
KPOTO, Robert Momo SINGBE, Sylvester Bondo Union of Liberian Democrats (ULD) 3,825 0.4%
KIADII, George Momodu MCGILL, Washington Shadrack National Vision Party of Liberia (NATVIPOL) 3,646 0.4%
DIVINE, SR., Samuel Raymond MAMU, SR., Jacob Gbanalagaye Independent 3,188 0.3%
REEVES, Alfred Garpee SHERIF, Martin Mohammed Njavola National Reformation Party (NRP) 3,156 .3%
;
proc print;
run;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Clearly, you have a "data source problem" which likely can be addressed using the DATA step technique, but you will want to use LENGTH or ATTRIB statements to declare in advance your SAS variables. Of course, it would be more effective from a data integrity perspective, to send your data back -- something not always possible.

Then code an INPUT statement but with no variables. You must use maybe the SCAN or other function(s) to "parse" your way through each record, with some inconsistent expectation about what's coming next.

So, explore using _INFILE_ as an input data buffer along with SCAN to create oversized temporary SAS variables -- then use CATX function to re-construct your permanent variables, as best you can. As one possibility, you can setup some general purpose DO UNTIL (); END; code paragraphs to scan through _INFILE_, creating your temporary variables.

Scott Barry
SBBWorks, Inc.
Patrick
Opal | Level 21
In addition to what Scott already said:

Once you've got the data in the data buffer (_infile_) you could also use Regulare Expressions to pick the substrings you need to populate your variables.

You could investigate prxsubstr and prxparse.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1617 views
  • 0 likes
  • 3 in conversation