BookmarkSubscribeRSS Feed
SixUnder
Obsidian | Level 7

My last one of these bad boys. Ok, so here goes...

 

Use the raw data file created previously. (ATTACHED)

 

Write a SAS® program that uses the PRINT procedure to produce a list that shows the contents of the raw data file. Illustrate that the gender categories of the original data were preserved. How about using the same proc print i used on the last question.

Proc print;
Title 'raw Data results';
*name of file;
Var Lowest_population Highest_population;
* would like those as headers, and list male, female on the left hand side;
*hrmm, will this work?;
run;

 

Write a second SAS® program to produce a report showing only the highest and lowest earning value or category for each gender. Ensure that labels are appropriate to convey the meaning of the data. Additionally, create a table that shows all of the earning variable contents for one gender category.

 

For the first part, highest and lowest, im taking that is the single lowest and highest for each gender, so the table will only have what 4 entries in it. The second part looks as if they want a list of each variable for all of one of the sexs. So, what about...this for the first part. I think this will do one of each entries, but not both, not sure on the proper method to single these out.

Proc print data=census;

Where sex='male';

Where Population>100000;

Run;

Proc print data=census;

Where sex='female';

Where population< 1;

Run;

For the second portion, would it be as simple as doing something like this? for all (variable) entries...

Data FullList;
	infile '.csv' DSD Missover firstobs=2;
	Input Gender $ Wages_Low Wages_High Estimated Max_Earnings;
Proc Print Data=FullList;
run;

Will this work? Am i on the right track?

 

Thanks!

 

26 REPLIES 26
Reeza
Super User

Neither are correct. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Several points:

Proc print;                               ** No dataset specified - always specify the dataset
Title 'raw Data results';                 ** Unless there is good reason keep titles outside procedures.
Var Lowest_population Highest_population;  
run;
Proc print data=census;
Where sex='male';
Where Population>100000;        ** Where clauses do not work like this
                                               ** Look into the "and" operator 
Run;

Proc print data=census;
Where sex='female';
Where population< 1;
Run;
Data FullList;
	infile '.csv' DSD Missover firstobs=2;        ** No filename specified
	Input Gender $ Wages_Low Wages_High Estimated Max_Earnings;  ** Don't use tab, this renders differently
** in different editors, use 2 spaces (can be configured in SAS options ** Missing run; Proc Print Data=FullList; run;

As an overview, nowadays it is far more important to make code as simple and readable as possible.  Consitent casing, indentations, finishing blaocks etc all contribute to this, so let me take your code (and I don't guarentee this will run as I don't have the census or csv file so can't check):

/* Assumes there is a dataset called work.census */
title 'raw Data results';
proc print data=work.census;
  var lowest_population highest_population;
run;

proc print data=census;
  where sex='male' and population > 100000;
run;

proc print data=census;
  where sex='female' and population < 1;
run;

/* Assumes there is a file on C drive call mydatafile.csv, and it is in the format given by the input line */
data work.fullList;
  infile 'c:\mydatafile.csv' dsd missover firstobs=2;
  input gender $ wages_low wages_high estimated max_Earnings;
run;

proc print data=fulllist;
run;

 

 

 

 

 

 

 

 

 

 

SixUnder
Obsidian | Level 7
yes there is a .csv file to infile at the proc step. As far as the data step at the beginning.... do i need to create a.....
data census; ?

As with my original code, this program is only giving me the one variable of each, where i need the lowest and highest of both male and female.
SixUnder
Obsidian | Level 7

where does the pdf i already have come into play? I see the fullist report. I get that, and it will display from my existing .csv delimited file. However, i need to generate those 4 required variables from the exising report, unless i am reading it wrong. I suppose i am just clarifying that the original lines under the title will read code from the pdf file i had previously.

 

 

Reeza
Super User

SAS can't read or combine PDFs, unless you're referring to text analytics and have SAS EM. 

 

The PDF cannot be incorporated into your solution. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

What PDF, I don't see a mention of it in your original post.  Make sure you clearly provide all information - provide example test data (in the form of a datastep) and what you want out at the end.  As for PDF, this is an "End Product" file format, and is of very little use trying to create anything from it.  You need to store the data which created that report, and use that data in the next run.

SixUnder
Obsidian | Level 7

PDF listed, and attached above.

 

SO your saying i need two .csv files  to generate this from?

SixUnder
Obsidian | Level 7
ods _all_ close;
ODS PDF FILE="/home//Program 1-results.pdf" startpage=NO;
TITLE COLOR=black 'Test';
title 'census';
proc print data=work.census;
  var lowest_population highest_population;
run;
proc print data=census;
  where sex='male' and population > 100000;
run;
proc print data=census;
  where sex='female' and population > 100000;
run;
proc print data=census;
  where sex='female' and population < 1;
run;
proc print data=census;
  where sex='male' and population < 1;
run;

data work.fullList;
  infile '/home/ Females Full Time Year Round.csv' dsd missover firstobs=2;
  input gender $ wages_low wages_high estimated max_Earnings;
run;

proc print data=fulllist;
run;
quit;

Ok, i have this written out. However as you will see i still have 4 errors of which all are the same. Can anyone help me with this?

 

Error Work.file.census does not exist, actually its in here 5 times. I understand it is because the datset is not there. Do i simply just need to add

 

data=work.file.census;

 

Or can anyone offer me a suggestion? I have my pdf imported, and the second portion requires the csv and its in there, however i still get that one error 5 times. I have it entered incorrectly, i thought perhaps someone could shed some light on where i have errored in my ways.

 

PDF, and CSV attached.

 

thanks!

 

62 title 'census';
63 proc print data=work.census;
ERROR: File WORK.CENSUS.DATA does not exist.
64 var lowest_population highest_population;
65 run;
 
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 67.28k
OS Memory 24488.00k
Timestamp 03/06/2017 10:22:52 PM
Step Count 71 Switch Count 30
Page Faults 0
Page Reclaims 11
Page Swaps 0
Voluntary Context Switches 64
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0
 
66
 
 
67 proc print data=census;
ERROR: File WORK.CENSUS.DATA does not exist.
68 where sex='male' and population > 100000;
WARNING: No data sets qualify for WHERE processing.
69 run;
 
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 75.59k
OS Memory 24488.00k
Timestamp 03/06/2017 10:22:52 PM
Step Count 72 Switch Count 32
Page Faults 0
Page Reclaims 10
Page Swaps 0
Voluntary Context Switches 72
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0
 
 
 
70 proc print data=census;
ERROR: File WORK.CENSUS.DATA does not exist.
71 where sex='female' and population > 100000;
WARNING: No data sets qualify for WHERE processing.
72 run;
 
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 75.43k
OS Memory 24488.00k
Timestamp 03/06/2017 10:22:52 PM
Step Count 73 Switch Count 32
Page Faults 0
Page Reclaims 10
Page Swaps 0
Voluntary Context Switches 72
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0
 
 
 
73 proc print data=census;
ERROR: File WORK.CENSUS.DATA does not exist.
74 where sex='female' and population < 1;
WARNING: No data sets qualify for WHERE processing.
75 run;
Reeza
Super User

ERROR: File WORK.CENSUS.DATA does not exist.

 

Where's the code that creates the Census dataset?

 

SixUnder
Obsidian | Level 7

No clue, thats the only error i have left. And no matter what i do its the same thing, im doing something wrong or leaving something out. I modified the code, and still have the same error 5x.

 

ods _all_ close;
ODS PDF FILE="//Program 1-results.pdf" startpage=NO;
TITLE COLOR=black 'Test';
title 'census';
data work.census;
  infile '/home/.csv' dsd missover firstobs=2;
  input gender $ wages_low wages_high estimated max_Earnings;
run;
proc print data=gender;
  var lowest_population highest_population;
run;

proc print data=gender;
  where sex='male' and population > 100000;
run;
proc print data=gender;
  where sex='female' and population > 100000;
run;
proc print data=gender;
  where sex='female' and population < 1;
run;
proc print data=gender;
  where sex='male' and population < 1;
run;

data work.fullList;
  infile '/home/ Females Full Time Year Round.csv' dsd missover firstobs=2;
  input gender $ wages_low wages_high estimated max_Earnings;
run;

proc print data=fulllist;
run;
quit;
Reeza
Super User

If you didn't import a datafile or save it from a previous session where are you expecting SAS to get the Census dataset from? You do have to provide the data....

SixUnder
Obsidian | Level 7

The PDF and the CSV files both contain the data for each part of the program.

Reeza
Super User

PDFs can't be used as a data source. 

 

Your code in the last post changed. There's an import as the first step, fix that and The rest of the errors will disappear. I'm 99% sure you did this in your last question. Not sure it was ever correct there either,  so I suggest reviewing how to import a CSV file. 

 

http://stats.idre.ucla.edu/sas/faq/how-do-i-read-in-a-delimited-ascii-file-in-sas/

SixUnder
Obsidian | Level 7

text file only?

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!

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.

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
  • 26 replies
  • 3198 views
  • 0 likes
  • 3 in conversation