BookmarkSubscribeRSS Feed
femiajumobi1
Quartz | Level 8

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
Quartz | Level 8

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
Quartz | Level 8

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
Quartz | Level 8

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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