BookmarkSubscribeRSS Feed
femiajumobi1
Obsidian | Level 7

Hi. I need to generate frequencies of specific variables (TEM and DHA) which has alphanumeric values

 

TEM has: TEM, TEM-1, TEM-1(b), TEM-10, TEM-10(e)

DHA has: NEG, DHA-1, DHA-15,DHA-TYPE,DHA

 

Proc freq data=AMR;
Tables TEM DHA;
run;

 

The SAS codes showed only the following.

femiajumobi1_0-1687203793328.png

it appears it did not read the alphanumeric values.Kindly suggest what needs to be done. Thanks

 

 

 

 

 

 

10 REPLIES 10
Reeza
Super User
Back up a step and ensure your data is read in correctly. How did you import your data into SAS?
femiajumobi1
Obsidian | Level 7

I imported the data (in csv) with this code

 

proc import datafile = "....csv"
out = Add
dbms = csv
replace;
run;

Reeza
Super User
PROC IMPORT guesses at the lengths.

Try adding GUESSINGROWS=MAX to the code or write your own data step to read the data in correctly, with the correct lengths and then recheck it.
femiajumobi1
Obsidian | Level 7

I added "guessingrows=max" but it gave this response

 

femiajumobi1_0-1687210988892.png

There is unending running of string variables in the log

femiajumobi1_1-1687211053026.png

I changed to "guessingrows=15, but the frequencies omitted the alphanumeric variables still. Kindly suggest a way forward. Thank you.

Reeza
Super User
Other option - manually write a data step to import the data. There should be code in the log. Copy, paste that and then modify it as necessary.
ballardw
Super User

The Log window full means that something about the file is generating lots of text. The most likely cause is something related to invalid data.

 

Question: did you ever open this CSV file in spreadsheet software? Did you SAVE it after opening with spreadsheet software? If the answer to both of these questions is YES then your file may have had the values changed by the spreadsheet and could be quite unreliable.

If the answer is know then open the CSV file in some text editing program like Notepad, copy the first 10 rows, then on the forum open a text box using the </> and paste the text. The text box is important to keep the forum from reformatting white space in text.

 

From what your picture shows I have feeling that your data file has many problems. Possibly related to line lengths and misaligned columns. I have a hard time believing that a column that would have value like "65-84 years" also has "<-0.06". That typically would indicate that a column, if the file is actually CSV, has 2 or more different types of values and that is not normal for a proper CSV file.

 

When you set Guessingrows to 15 that is even fewer rows than the default.

femiajumobi1
Obsidian | Level 7

Thanks. Writing the datastep  as shown below does not help either.

 

%let path=C:\...;
options validvarname=v7;

proc import datafile="&path\....csv"
out=add
dbms=csv replace;
guessingrows=max;
run;

Reeza
Super User

The code you posted is not a data step, that's still proc import. A data step would look something like this:

 

data add;
infile "&path\...csv" dsd truncover;
informat var1 $8. var2 8. var3 8. var4 $12.;
input var1 var2 var3 var4;
run;

Here's a short tutorial on how to do so, and as mentioned previously PROC IMPORT puts the code it uses in the log. You can copy it and modify the type/format as needed for your data.

 

http://eta.health.usf.edu/publichealth/PHC6701/presentations/2013/readingExternalFilesSAS.pdf

 


@femiajumobi1 wrote:

Thanks. Writing the datastep  as shown below does not help either.

 

%let path=C:\...;
options validvarname=v7;

proc import datafile="&path\....csv"
out=add
dbms=csv replace;
guessingrows=max;
run;


 

Kurt_Bremser
Super User

@femiajumobi1 wrote:

Thanks. Writing the datastep  as shown below does not help either.

 

%let path=C:\...;
options validvarname=v7;

proc import datafile="&path\....csv"
out=add
dbms=csv replace;
guessingrows=max;
run;


This is NOT a DATA step.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 712 views
  • 0 likes
  • 4 in conversation