BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dumi1
Fluorite | Level 6

Hi Guys. Please help. I need to create a script that shows me how many records and variables are in that text file I'm working on

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Not possible.

Text files don't have variables. SAS data sets have variables.

When reading a text file into a SAS data set it is possible to combine five lines of text into a single observation. It is also possible to create three observations from a single line of text.

Some things are possible. You can count the number of lines of text. With a little programming you can count the maximum number of commas in the first few lines of text. But you can't report on variables when there are no variables.

View solution in original post

7 REPLIES 7
Amir
PROC Star

Can you show us a sample / example of the text file and how variables are delimited, e.g., tab character, comma, column position, etc.

 

Is the text file on Unix / Linux or DOS / Windows or Mainframe Operating System?

 

Any other information you could supply that you think would be useful.

 

 

Kind regards,

Amir.

Astounding
PROC Star
Not possible.

Text files don't have variables. SAS data sets have variables.

When reading a text file into a SAS data set it is possible to combine five lines of text into a single observation. It is also possible to create three observations from a single line of text.

Some things are possible. You can count the number of lines of text. With a little programming you can count the maximum number of commas in the first few lines of text. But you can't report on variables when there are no variables.
Dumi1
Fluorite | Level 6

this is what I mean, I need to make sure that on the text files that am working on all this exacts headers are in the text file and currently I have to manually open the text file and make sure all these headers are on the text file so I'm wondering if there's any script to run that will show me that there's 532 headers in that file, not more not less because if theres more it means I have run a wrong product. This is part of my QA. Please help

HD003EQ001EQ002EQ003EQ004EQ005EQ006EQ007EQ008EQ009EQ010EQ011EQ012EQ013EQ014EQ015EQ016EQ017EQ018EQ019EQ020EQ021EQ022EQ023EQ024EQ025EQ026EQ027EQ028EQ029EQ030EQ034EQ035EQ036EQ037EQ038EQ039EQ040EQ041EQ042EQ043EQ044EQ045EQ046EQ047EQ048EQ049NQ001NQ002NQ003NQ007NQ008NQ009NQ010NQ011NQ012NQ013NQ014NQ015NQ016NQ017NQ018NQ019NQ020NQ021DF001DF002DF005DF006DF007DF008DF009DF010DF011DF015DF016DF023DF024DF025DF026DF027DF028JD001JD005JD006JD007JD008JD009JD010JD011JD012JD013JD014JD015JD016JD018JD020JD022JD023JD024JD025NG001NG005NG006NG007NG008NG009NG010NG011NG012NG013NG014NG024NG025NT001NT009NT010NT011NT012NT013NT014NT015NT016TA001TA002TA003TA004TA005TA006TA007PP001PP002PP003PP004PP005PP006PP010PP011PP012PP016PP018PP019PP020PP021PP023PP024PP025PP026PP028PP029PP030PP031PP032PP033PP035PP039PP040PP041PP042PP043PP044PP045PP046PP047PP049PP050PP059PP063PP074PP089PP103PP105PP106PP107PP108PP109PP110PP111PP112PP113PP114PP115PP116PP126PP135PP136PP137PP138PP139PP140PP141PP142PP143PP144PP145PP146PP147PP148PP149PP150PP151PP152PP153PP154PP155PP156PP157PP158PP159PP160PP161PP162PP163PP164PP165PP166PP167PP168PP169PP170PP171PP172PP173PP174PP175PP176PP177PP178PP179PP180PP181PP182PP183PP186PP187PP188PP189PP190PP191PP192PP193PP194PP195PP196PP197PP198PP199PP200PP201PP202PP203PP204PP205PP206PP207PP208PP209PP210PP211PP212PP213PP214PP215PP216PP217PP218PP219PP220PP221PP222PP223PP224PP225PP226PP227PP228PP229PP230PP231PP232PP233PP237PP238PP239PP240PP241PP242PP243PP244PP245PP246PP247PP248PP249PP250PP251PP252PP253PP254PP255PP256PP257PP258PP259PP260PP261PP262PP263PP264PP290PP291PP292PP293PP294PP295PP296PP297PP298PP301PP302PP303PP304PP305PP306PP307PP308PP309PP310PP311PP312PP313PP314PP315PP316PP317PP318PP319PP320PP321PP322PP323PP324PP325PP326PP327PP328PP329PP330PP331PP332PP333PP334PP335PP336PP337PP338PP339PP340PP341PP342PP343PP344PP345PP346PP347PP348PP349PP350PP351PP352PP353PP354PP355PP356PP357PP358PP359PP360PP361PP362PP363PP364PP365PP366PP367PP368PP369RE001RE002RE003RE004RE005RE006RE015RE020RE021RE022IN001IN002IN003IN004IN005IN006IN020IN021IN022DP001DP010DP013DP018JN001JN010JN013JN018SP001SP003SP004SP006SP007SP009SP010SP012SP013SP015NP001NP002NP003NP004NP005NP006NP010NP011NP012NP016NP017NP018NP019NP020NP021NP022NP023NP024NP025NP031NP033NP039NP040NP041NP042NP044NP045NP047NP057NP103NP104NP105NP106NP107NP108NP109NP110NP111NP113NP147NP186NP187NP188NP189NP190NP191NP192NP193NP194NP195NP196NP197NP198NP199NP200NP201NP202NP203NP204NP205NP206NP207NP208NP209NP210NP211NP212NP213NP214NP215NP216NP217NP218NP219NP220NP221NP222NP223NP224NP225NP226NP227NP228NP229NP230NP231NP232NP233NP239NP240NP241NP242NP243NP244NP245NP246NP247NP262NP278NP279NP280NP281NP282NP283NP284NP285NP286
Tom
Super User Tom
Super User

What does your text file look like?  What you posted into the forum looks like an HTML table.  Perhaps that is because your text file is using tabs as the delimiter? Perhaps it is because you opened the text file with Excel or some other program that converted the text into cells in a table?

 

You might want to also look at the names of the columns and not just the number of them to make sure you have the right file.

 

So if the file is using TAB as the delimiter and there are no more than 1,000,000 bytes in the first line here is a program generate a dataset with the names of the columns.  It will also print the number of columns in the log and set a macro variable to the number. For other delimiters change the DLM= (aka DELIMITER=) option.

data  names ;
  if eof then do;
    put 'There are ' column 'columns in this file.';
    call symputx('num_columns',column);
  end;
  infile 'myfile' dsd dlm='09'x truncover end=eof lrecl=1000000 obs=1;
  column+1;
  input name :$32. @@;
run;

 

Dumi1
Fluorite | Level 6

yes the file is tab delimited and I opened the text file with excel so that I can count the number of headers.

 

Thank you so much, I'll try this script

Tom
Super User Tom
Super User

You use '09'x to represent a TAB in the infile statement.  Also make sure to include OBS=1 in the infile statement or it will read the whole file!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 7 replies
  • 930 views
  • 1 like
  • 5 in conversation